错误原因:java.lang.ClassCastException:

时间:2019-05-06 00:49:05

标签: android

enter image description here

我正在android studio中创建一个聊天程序,当我运行该程序时,一切都伴随着绿色的kes气,但是在日志中,我收到以下错误,并发送给我以纠正主活动中的问题,在emoludar中打开应用程序并关闭它。

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: mensajeria.chatappsistema, PID: 11008
    java.lang.RuntimeException: Unable to start activity ComponentInfo{mensajeria.chatappsistema/mensajeria.chatappsistema.MainActivity}: java.lang.ClassCastException: android.support.v7.app.AlertController$RecycleListView cannot be cast to android.support.v7.widget.RecyclerView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        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:807)
     Caused by: java.lang.ClassCastException: android.support.v7.app.AlertController$RecycleListView cannot be cast to android.support.v7.widget.RecyclerView
        at mensajeria.chatappsistema.MainActivity.onCreate(MainActivity.java:38)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        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:807) 
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
Application terminated.

1 个答案:

答案 0 :(得分:0)

在XML文件中,您正在使用不同的recyclerview,而在Java中,您正在投射不同的recyclerview,这就是错误即将来临的原因。在XML和Java文件中使用相同类型的recyclerview。