android.view.inflateexception我遇到了这个错误

bqf10yzr  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(177)

我试过使用速度表视图。我完成了安装库所需的操作,但仍然出现错误。当我尝试运行应用程序时,出现以下错误:android.view.inflateexception我该怎么办?
这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.  
widget.ConstraintLayout 
xmlns:android="http://schemas. 
android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res- 
auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
    android:id="@+id/speedResultTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/speedTest_textview_hint"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view_speed"
    app:layout_constraintVertical_bias="0.3" />

<com.github.anastr.speedviewlib.AwesomeSpeedometer
    android:id="@+id/view_speed"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="76dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.496"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:sv_minSpeed="0"
    app:sv_maxSpeed="200"
    app:sv_unit="@string/speed_unit"
    app:sv_startDegree="180"
    app:sv_endDegree="360"
    app:sv_withIndicatorLight="true"
    app:sv_indicatorLightColor="#BB0000FF"
    tools:ignore="MissingConstraints" />

</androidx.constraintlayout. 
widget.ConstraintLayout>

这是我的主要活动

package com.enes.speedmeter;
import androidx.appcompat.app.AppCompatActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import 
com.github.anastr. 
speedviewlib.AwesomeSpeedometer;
import 
com.github.anastr.speedviewlib.SpeedView;

import java.math.BigDecimal;

import fr.bmartel.speedtest.SpeedTestReport;
import fr.bmartel.speedtest.SpeedTestSocket;
import 
fr.bmartel.speedtest.inter.ISpeedTestListener;
import 
fr.bmartel.speedtest.model.SpeedTestError;

public class MainActivity extends 
AppCompatActivity {

SpeedView speedView;
SpeedTestSocket speedTestSocket;
TextView resultTestTxt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    define();
    SpeedTask speedTask = new SpeedTask();
    speedTask.execute();

}

public void define(){
    speedView = findViewById(R.id.view_speed);
    speedTestSocket = new SpeedTestSocket();
    resultTestTxt = findViewById(R.id.speedResultTextView);
}

public int bitToMegaBit(BigDecimal bit){
    BigDecimal instantaneousSpeed= bit;
    BigDecimal resultSpeed = instantaneousSpeed.multiply(BigDecimal.valueOf(Math.pow(10.0,-6.0)));
    int resultSpeedInt = resultSpeed.intValue();
    return resultSpeedInt;
}

class SpeedTask extends AsyncTask<Void,Void,Void>{

    @Override
    protected Void doInBackground(Void... voids) {
        speedTestSocket.addSpeedTestListener(new ISpeedTestListener() {
            @Override
            public void onCompletion(SpeedTestReport report) {

                Toast.makeText(MainActivity.this, ""+R.string.speedTest_completion_message, Toast.LENGTH_SHORT).show();

                resultTestTxt.setText(bitToMegaBit(report.getTransferRateBit()));
            }

            @Override
            public void onProgress(float percent, SpeedTestReport report) {
                //converting bit rate to Mbps and giving as a parameter to speedViev

                speedView.speedTo(bitToMegaBit(report.getTransferRateBit()));
            }

            @Override
            public void onError(SpeedTestError speedTestError, String errorMessage) {
                Toast.makeText(MainActivity.this, ""+ errorMessage, Toast.LENGTH_SHORT).show();

            }
        });

        speedTestSocket.startDownload("http://ipv4.ikoula.testdebit.info/1M.iso");
        return null;
    }
}

}

有人知道这个问题吗?提前谢谢。我怎样才能解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题