ConstraintLayout时出错

ConstraintLayout时出错

本文介绍了膨胀类android.support.constraint.ConstraintLayout时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到此错误时,我正在使用Android Studio应用程序.

I was working on an Android Studio application when I ran into this error.

    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)

这是我的礼物:

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文件中的约束布局标记

This is the constraint layout tag in my xml file

<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' )我仍然遇到相同的错误.我怎样才能解决这个问题?

I have looked into my error on this site and google, and the common answer is to add compile 'com.android.support.constraint:constraint-layout:1.0.2', however compile is now obsolete, and when I replace compile with implementation and changed it to the newest version ('com.android.support.constraint:constraint-layout:2.0.0-beta1') I still run into the same error. How can I fix this?

推荐答案

如果您正在使用androidX软件包,或者要在项目中使用它们,则必须将项目迁移到androidX.为此,您需要执行以下步骤:

If you are using androidX packages or you want to use them for your project, then you have to migrate your project to androidX. For that you need to follow below steps:

1)在Android Studio中,只需转到 Refactor-> Migrate to AndroidX 即可迁移项目,如果在迁移项目时遇到问题,则可以在那里备份项目.

1) In Android Studio, just goto Refactor-> Migrate to AndroidX to migrate your project and there you can backup your project if some problem occurs migrating project.

此后,您的dependendencies将自动具有androidX软件包.

After that your dependendencies will have androidX packages automatically.

进一步阅读:此处

这篇关于膨胀类android.support.constraint.ConstraintLayout时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:20