我无法从我的Android应用服务发送通知,这是我的错误日志
01-03 20:41:01.075: W/dalvikvm(7009): threadid=11: thread exiting with uncaught exception (group=0x40fcd2a0)
01-03 20:26:31.795: E/AndroidRuntime(4186): FATAL EXCEPTION: Thread-1428
01-03 20:26:31.795: E/AndroidRuntime(4186): java.lang.NullPointerException
01-03 20:26:31.795: E/AndroidRuntime(4186): at android.content.ComponentName.<init>(ComponentName.java:75)
01-03 20:26:31.795: E/AndroidRuntime(4186): at android.content.Intent.<init>(Intent.java:3615)
这是我服务中的代码
int noid = 1;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title")
.setContentText("Text message");
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(noid, mBuilder.build());
请帮忙
谢谢
答案 0 :(得分:2)
您传递给Context
构造函数的Intent
为null
。
Service
是Context
所以在Service
中你可以使用this
作为上下文。