首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >带有appcompat的Android ClassNotFoundException -v7:28.0.0

带有appcompat的Android ClassNotFoundException -v7:28.0.0
EN

Stack Overflow用户
提问于 2019-05-21 04:18:11
回答 2查看 2.7K关注 0票数 5

我正在开发一个Android应用程序,并尝试使用工具栏为其添加一些功能;这就是我使用appcompat-v7模块的原因。我遵循了this教程(抱歉,因为它是西班牙语的),我已经用兼容性支持包更新了我的集成开发环境,我还在我的Gradle文件中添加了新的模块,我已经用这个新的工具栏更新了我的应用程序的设计XML (我可以在设计编辑器中看到这个工具栏)。

但是,当我启动我的应用程序时,我得到以下错误:

代码语言:javascript
复制
     java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
     Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/base.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_resources_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(...

我的gradle文件:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.gomar.gomar_sanidad"
        minSdkVersion 21
        targetSdkVersion 28
        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.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

带有工具栏(Design XML)的activity_main.xml示例:

代码语言:javascript
复制
    <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=".NuevaFicha">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="0dp"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
        app:layout_constraintVertical_bias="0.0">
        ....

我已经尝试了所谓的here (检查is,清理项目,无效缓存...)但这些解决方案都没有达到预期的效果。你有什么想法吗?

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-21 05:00:36

您同时使用了androidx和AppCompat,因此error.consider使用其中任何一个。

代码语言:javascript
复制
 implementation 'com.android.support:appcompat-v7:28.0.0' //this is appcompat

    implementation 'androidx.appcompat:appcompat:1.0.0-beta01' //this is android x

你不能同时使用androidx和android支持。

请参阅how to migrate to androidX

票数 3
EN

Stack Overflow用户

发布于 2020-05-28 07:20:13

如果您的gradle.properties文件设置了如下属性

代码语言:javascript
复制
android.useAndroidX=true

替换

代码语言:javascript
复制
android.support.v7.widget.Toolbar

使用

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

https://stackoverflow.com/questions/56227627

复制
相关文章

相似问题

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