迁移到androidx后,膨胀androidx.recyclerview.widget.RecyclerView类会发生错误

时间:2019-10-28 14:48:03

标签: xml android-studio android-layout android-recyclerview androidx

我刚刚通过Android Studio菜单选项Refactor-> Refactor to AndroidX迁移到androidx

我遇到以下错误:

android.view.InflateException:二进制XML文件第2行:膨胀类androidx.recyclerview.widget.RecyclerView时出错

有什么主意吗?

Stacktrace:

10-28 20:01:59.913 13394-13394/com.example.impwala E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.impwala, PID: 13394
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.impwala/com.example.impwala.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.recyclerview.widget.RecyclerView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2235)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:212)
        at android.app.ActivityThread.main(ActivityThread.java:5133)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.recyclerview.widget.RecyclerView
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.impwala.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:5243)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 
        at android.app.ActivityThread.access$800(ActivityThread.java:144) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:212) 
        at android.app.ActivityThread.main(ActivityThread.java:5133) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at android.view.LayoutInflater.createView(LayoutInflater.java:594)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
        at com.example.impwala.MainActivity.onCreate(MainActivity.java:12) 
        at android.app.Activity.performCreate(Activity.java:5243) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 
        at android.app.ActivityThread.access$800(ActivityThread.java:144) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:212) 
        at android.app.ActivityThread.main(ActivityThread.java:5133) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.OutOfMemoryError
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
        at android.content.res.Resources.loadDrawable(Resources.java:2129)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
        at android.view.View.<init>(View.java:3685)
        at android.view.ViewGroup.<init>(ViewGroup.java:470)
        at androidx.recyclerview.widget.RecyclerView.<init>(RecyclerView.java:651)
        at androidx.recyclerview.widget.RecyclerView.<init>(RecyclerView.java:647)
        at java.lang.reflect.Constructor.constructNative(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
        at com.example.impwala.MainActivity.onCreate(MainActivity.java:12) 
        at android.app.Activity.performCreate(Activity.java:5243) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 
        at android.app.ActivityThread.access$800(ActivityThread.java:144) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:212) 
        at android.app.ActivityThread.main(ActivityThread.java:5133) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691) 
        at dalvik.system.NativeStart.main(Native Method) 


我已经尝试过此问题的答案,但他们没有帮助我

Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx

2 个答案:

答案 0 :(得分:0)

我将XML中的签名更改为androidx.recyclerview.widget.RecyclerView并有效。

答案 1 :(得分:0)

首先在 XML 文件中确保你有这个签名

androidx.recyclerview.widget.RecyclerView 

如果你有的话

打开logcat 并阅读整个错误。您可能会看到由 .. 引起的,这是您的实际错误 对我来说是@dimen/somedimen。我写的值是 10,所以当我修复它时是 10dp。我的问题解决了。