我正在尝试将一个数组列表从活动传递到小部件,但我的应用程序在我的小部件提供程序中崩溃了。
我在下面给出了详细信息。
这是我第一个活动的部分代码:
Intent intent1 = new Intent(MainActivity.this,
AppProviderWidget.class);
intent1.setAction("android.appwidget.action.APPWIDGET_UPDATE");
// Use an array and EXTRA_APPWIDGET_IDS instead of
// AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
int[] ids = widgetIDs;
intent1.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
intent1.putExtra("widgetlist", result);
sendBroadcast(intent1);
我发送的数据在这里:
intent1.putExtra("widgetlist", result);
以及来自 AppProviderWidget onReceive 方法的代码
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
ArrayList<DuyuruHaber> arl = new ArrayList<DuyuruHaber>();
arl = (ArrayList<DuyuruHaber>) intent
.getSerializableExtra("widgetlist");
try {
liste = arl;
} catch (Exception e) {
Log.w("Log",e.toString());
}}
AppProviderWidget.onReceive(AppProviderWidget.java:170)
arl = (ArrayList<DuyuruHaber>) intent
.getSerializableExtra("widgetlist");
我的原木猫
08-23 16:28:01.684: E/AndroidRuntime(10067): FATAL EXCEPTION: main
08-23 16:28:01.684: E/AndroidRuntime(10067): java.lang.RuntimeException: Unable to start receiver widget.AppProviderWidget: java.lang.NullPointerException
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.os.Looper.loop(Looper.java:123)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-23 16:28:01.684: E/AndroidRuntime(10067): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 16:28:01.684: E/AndroidRuntime(10067): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 16:28:01.684: E/AndroidRuntime(10067): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-23 16:28:01.684: E/AndroidRuntime(10067): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-23 16:28:01.684: E/AndroidRuntime(10067): at dalvik.system.NativeStart.main(Native Method)
08-23 16:28:01.684: E/AndroidRuntime(10067): Caused by: java.lang.NullPointerException
08-23 16:28:01.684: E/AndroidRuntime(10067): at widget.AppProviderWidget.onReceive(AppProviderWidget.java:170)
08-23 16:28:01.684: E/AndroidRuntime(10067): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
谢谢您的帮助。