温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android - java.lang.ClassCastException: cannot be cast to

发布时间:2020-07-14 21:32:27 来源:网络 阅读:2017 作者:xjhznick 栏目:移动开发

Error:

 threadid=1: thread exiting with uncaught exception (group=0x415c5940)

 FATAL EXCEPTION: main

 java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.p2p.CONNECTION_STATE_CHANGE flg=0x28000010 (has extras) } in com.example.wifidirectdemo.WifiDirectBroadcastReceiver@421207d0

 at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:791)

 at android.os.Handler.handleCallback(Handler.java:730)

 at android.os.Handler.dispatchMessage(Handler.java:92)

 at android.os.Looper.loop(Looper.java:137)

 at android.app.ActivityThread.main(ActivityThread.java:5265)

 at java.lang.reflect.Method.invokeNative(Native Method)

 at java.lang.reflect.Method.invoke(Method.java:525)

 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:760)

 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)

 at dalvik.system.NativeStart.main(Native Method)

 Caused by: java.lang.ClassCastException: com.example.wifidirectdemo.DeviceListFragment cannot be cast to com.example.wifidirectdemo.DeviceDetailFragment

 at com.example.wifidirectdemo.MainActivity.resetData(MainActivity.java:76)

 at com.example.wifidirectdemo.WifiDirectBroadcastReceiver.onReceive(WifiDirectBroadcastReceiver.java:61)

 at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:770)

 ... 9 more

进过检查发现问题出在xml配置文件:

Android - java.lang.ClassCastException:  cannot be cast to

    第二个fragment的名称应该是DeviceDetailFragment,代码Java代码没有问题,在绑定组件时出现问题,从而导致Class需要强行转换并失败。


    结合上一次组件未在Java代码中绑定出现的空指针异常,已经连续两个错误出现在xml布局文件和Java代码交互上了,代码运行出现问题,不能只盯着功能代码(Java)。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI