首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android片段ClassNotFoundException:找不到类android.support.constraint.ConstraintLayout

Android片段ClassNotFoundException:找不到类android.support.constraint.ConstraintLayout
EN

Stack Overflow用户
提问于 2020-05-17 14:24:42
回答 1查看 86关注 0票数 0

即使新创建的片段也能正常工作,但是如果我转到旧的片段类,应用程序就会停止工作,我可以在控制台中看到错误:

代码语言:javascript
运行
复制
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.singeek.nav.pmcalculator/com.singeek.nav.pmcalculator.OptionActivity}: 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:2805)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
     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.singeek.nav.pmcalculator--icu9YauYQyfz4UoNRwBLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.singeek.nav.pmcalculator--icu9YauYQyfz4UoNRwBLQ==/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:606)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.singeek.nav.pmcalculator.OptionActivity.onCreate(OptionActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Activity.performCreate(Activity.java:7014)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

但是,在片段的XML布局文件中,我也看到了以下错误:

无法找到以下类:- android.support.constraint.ConstraintLayout (向项目添加约束-布局库依赖关系,修复构建路径,编辑XML,创建类)提示:尝试构建项目。

以下是build.gradle文件:

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'   //added when firebase connected
apply plugin: 'com.google.gms.google-services'     //added when firebase connected

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.singeek.nav.bakercalculator"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            //    useProguard true
            shrinkResources true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    androidTestImplementation 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta5"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.hotchemi:android-rate:1.0.1'
    implementation 'com.google.firebase:firebase-auth:19.3.1'   //added when firebase connected
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.facebook.android:facebook-login:[5,6)'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

}

XML布局文件:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentA">

    <!-- TODO: Update blank fragment layout -->

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <EditText
                android:id="@+id/doughNameBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="@string/enter_recipe_name"
                android:inputType="textPersonName" />

            <TableLayout
                android:id="@+id/ingredientTable"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stretchColumns="0,1">

            </TableLayout>

            <Button
                android:id="@+id/add_ingredient"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoSizeMaxTextSize="12dp"
                android:autoSizeMinTextSize="2dp"
                android:autoSizeTextType="uniform"
                android:background="@color/colorPrimary"
                android:drawableLeft="@drawable/ic_plus"

                android:singleLine="true"
                android:text="Add Ingredient"
                android:textColor="@android:color/white"

                />

            <Button
                android:id="@+id/generateButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/generateButton" />
        </LinearLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-17 14:27:51

既然你用的是雄激素,请用这条路-

代码语言:javascript
运行
复制
androidx.constraintlayout.widget.ConstraintLayout
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61853370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档