Did not find class android support design widget CoordinatorLayout

最近要维护一个旧项目,接了新的功能,但新功能需要用到新的模块,所以吧啦啦的把旧有的代码都替换为新的Androidx了,原本编译没有报错,心想不太难,但是运行起来,直接挂了。。。。下面是错误的代码:

2019-12-20 15:51:31.670 8729-8729/com.reach.reachplayer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.reach.reachplayer, PID: 8729
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reach.reachplayer/com.reach.reachplayer.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
     Caused by: android.view.InflateException: Binary XML file line #2: 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.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data/app/com.reach.reachplayer-QQnkS0v4W79B6CnLlq0a-Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.reach.reachplayer-QQnkS0v4W79B6CnLlq0a-Q==/lib/arm, /data/app/com.reach.reachplayer-QQnkS0v4W79B6CnLlq0a-Q==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /product/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:613)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
        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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:477)
        at com.android.internal.policy.HwPhoneWindow.setContentView(HwPhoneWindow.java:321)
        at android.app.Activity.setContentView(Activity.java:2839)
        at com.reach.reachplayer.BaseActivity.setContentView(BaseActivity.java:20)
        at com.reach.reachplayer.MainActivity.onCreate(MainActivity.java:74)
        at android.app.Activity.performCreate(Activity.java:7372)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

 

在网上找了很多方法,概括起来就是两种方法,一是AndroidManifest里的主题,另一种就是在build.gradle里添加新的依赖,但都是没有作用。

 

后来想到是替换了新的androidx,那既然这样,可以把红框里的替换为androidx:

替换androidx的一段代码如下面所示:

androidx.coordinatorlayout.widget.CoordinatorLayout

替换后的截图: 

 

后记,替换为androidx后,有很多地方都出错了,报的都是和这个类似的错误,如下所示:

所以解决办法都是把报错的xml文件替换为androidx即可~

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值