gpt4 book ai didi

android - 迁移到 androidx 后膨胀类 android.support.design.widget.CoordinatorLayout 时出错

转载 作者:行者123 更新时间:2023-11-29 02:22:45 27 4
gpt4 key购买 nike

我刚刚迁移到 Androidx,但迁移后出现以下错误:

Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout`

有什么想法吗?

堆栈跟踪:

 Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43)
at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22)
        compileSdkVersion 28
minSdkVersion 18
targetSdkVersion 28


dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
} ```



最佳答案

迁移到 Androidx 后,我有类似的经历。我按照以下步骤解决了问题:[1]确保布局文件使用这个

 <androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

[2]如果 Android Studio 在迁移到 Androidx 后未更改支持库导入,请执行此步骤。

转到类文件(java 或 kt),删除与以前的库相关的所有导入,并允许 Android Studio 导入适当的 Androidx 库。对所有其他迁移问题执行这些操作。

这是你的依赖项应该是这样的:

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.drawerlayout:drawerlayout:1.0.0' //DrawerLayout
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0' //androidx AppBarLayout, CollapsingToolbarLayout etc.
implementation 'androidx.webkit:webkit:1.0.0' //androidx webview

关于android - 迁移到 androidx 后膨胀类 android.support.design.widget.CoordinatorLayout 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54275651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com