我在运行 Android 4.0.4 的摩托罗拉 Xoom 上遇到我的小部件崩溃。
这是堆栈跟踪:
09-24 15:03:33.288: E/AndroidRuntime(4719): FATAL EXCEPTION: main
09-24 15:03:33.288: E/AndroidRuntime(4719): java.lang.RuntimeException: Unable to start receiver com.chaitanya.widgets.MyWidgetProvider: java.lang.NullPointerException
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2126)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.os.Handler.dispatchMessage(Handler.java:99)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.os.Looper.loop(Looper.java:137)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-24 15:03:33.288: E/AndroidRuntime(4719): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 15:03:33.288: E/AndroidRuntime(4719): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 15:03:33.288: E/AndroidRuntime(4719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-24 15:03:33.288: E/AndroidRuntime(4719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-24 15:03:33.288: E/AndroidRuntime(4719): at dalvik.system.NativeStart.main(Native Method)
09-24 15:03:33.288: E/AndroidRuntime(4719): Caused by: java.lang.NullPointerException
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.widget.RemoteViews$SetOnClickPendingIntent.writeToParcel(RemoteViews.java:436)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.widget.RemoteViews.writeToParcel(RemoteViews.java:1655)
09-24 15:03:33.288: E/AndroidRuntime(4719): at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:435)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:247)
09-24 15:03:33.288: E/AndroidRuntime(4719): at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:270)
<my code that calls updateAppWidget>
我的代码监听来自我的应用程序的某些广播并动态更新小部件视图。在此过程中,它会删除一些现有视图(设置为Visibility.GONE
),并通过将它们设置为 来清除 PendingIntents null
。毕竟,它调用AppWidgetManager.updateAppWidget()
.
现在,这在 4.1.2 设备和 4.3 设备上都可以正常工作,但是在 4.0.4 设备上会出现这种崩溃。我已经搜索了很多,并尝试了很多 Intent 选项,但我无法解决这个问题。有没有人经历过这个?任何指针?
谢谢!