我是一个乞丐,在我的应用程序中,我有一个通知用于图像上传进度,我想添加一个带有通知的button
,当用户点击button
时,我想取消上传服务。我使用了下面的代码,我已经为button
创建了一个xm
l布局,
mBuilder = new android.support.v4.app.NotificationCompat.Builder(ImageUploadActivity.this);
mBuilder.setContentTitle("Cookbook Upload")
.setContentText("Upload in Progress")
.setTicker("Cookbook Upload")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.build();
RemoteViews contentView=new RemoteViews(ctx.getPackageName(), R.layout.activity_upload);
但是当我运行应用程序时,它会在这一行抛出空指针异常
RemoteViews contentView=new RemoteViews(ctx.getPackageName(), R.layout.activity_upload);
我不明白这是怎么发生的,有人能帮帮我吗?Logcat
07-17 15:06:34.733 21652-21879/? E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[MyIntentService]
java.lang.NullPointerException
at project1.jbn.com.cookbookintent.ImageUploadActivity.onHandleIntent(ImageUploadActivity.java:67)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
但是当我运行应用程序时,它会抛出一个空指针异常line RemoteViews contentView=new RemoteViews(ctx.getPackageName(), R.layout.activity_upload);
则ctx
没有初始化,您不需要它,因为ImageUploadActivity.this
已经是一个上下文