错误夸大类Android.support.constraint.constraintlayout



我在遇到此错误时正在研究Android Studio应用程序。

    Process: com.example.visualizercopy, PID: 28098
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.visualizercopy/io.esense.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2812)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6317)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
     Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.visualizercopy-1/base.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.visualizercopy-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.visualizercopy-1/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:609)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:424)
        at android.app.Activity.setContentView(Activity.java:2471)
        at io.esense.MainActivity.onCreate(MainActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:6757)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2704)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2812)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6317)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
2019-06-23 16:25:42.234 28098-28098/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

这是我的gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.visualizercopy"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
    implementation 'com.jjoe64:graphview:4.2.2'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

这是我XML文件中的约束布局标签

<android.support.constraint.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:id="@+id/PLAY_PARENT"
    android:padding="0dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="81dp">

我已经在此站点和Google上研究了我的错误,而常见的答案是添加compile 'com.android.support.constraint:constraint-layout:1.0.2',但是现在已过时编译,当我用实现替换编译并将其更改为最新版本('com.android.support.constraint:constraint-layout:2.0.0-beta1'(时,我仍然运行陷入相同的错误。我怎样才能解决这个问题?

我弄清楚了,我必须将 android.support.constraint.ConstraintLayout标记更新为我的布局xml中的 androidx.constraintlayout.widget.ConstraintLayout

您正在使用Androidx软件包。因此,您必须使用Androidx迁移所有Android库。

因此,在gradle中替换了下面的线,

implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'

这样,

implementation 'androidx.constraintlayout:constraintlayout:1.1.2' 

参考此处。

如果您使用的是androidX软件包或要将它们用于项目,则必须将项目迁移到androidX。为此,您需要遵循以下步骤:

1(在Android Studio中,只需goto Refactor-> Migrate to AndroidX 迁移您的项目,如果某些问题迁移了项目,则可以备份项目。

之后,您的dependendencies将自动具有androidX包。

进一步阅读:这里

相关内容

  • 没有找到相关文章