使用广播接收器时出错
Error when using Broadcast receiver
我在尝试使用广播接收器侦听网络连接状态的变化时收到 manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl 运行时异常。你能帮我吗?
堆栈跟踪是 -
java.lang.RuntimeException: Unable to start receiver com.amazonaws.cognito.sync.demo.NetworkChangeReceiver: java.lang.ClassCastException: manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2452)
at android.app.ActivityThread.access00(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
我从 github 博客中找到了解决您问题的方法,而不是在我的 Android manifest.xml 文件中注册接收器,而是在自定义应用程序中声明并注册它 class。那解决了问题。
我在尝试使用广播接收器侦听网络连接状态的变化时收到 manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl 运行时异常。你能帮我吗? 堆栈跟踪是 -
java.lang.RuntimeException: Unable to start receiver com.amazonaws.cognito.sync.demo.NetworkChangeReceiver: java.lang.ClassCastException: manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2452)
at android.app.ActivityThread.access00(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
我从 github 博客中找到了解决您问题的方法,而不是在我的 Android manifest.xml 文件中注册接收器,而是在自定义应用程序中声明并注册它 class。那解决了问题。