2013-12-15 64 views
1

我想創建一個通知,但應用程序在調用最後一行後崩潰。顯示通知後崩潰應用程序

NotificationCompat.Builder notification = 
      new NotificationCompat.Builder(this) 
      .setContentTitle("My notification") 
      .setContentText("Hello World!"); 

    NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    mNotificationManager.notify(1, notification.build()); 

在logcat中,我發現這一點:

12-15 19:30:27.828: W/dalvikvm(22020): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
12-15 19:30:27.838: E/AndroidRuntime(22020): FATAL EXCEPTION: main 
12-15 19:30:27.838: E/AndroidRuntime(22020): java.lang.IllegalArgumentException: contentIntent required: pkg=com.example.test id=1 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x0) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Parcel.readException(Parcel.java:1326) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Parcel.readException(Parcel.java:1276) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.NotificationManager.notify(NotificationManager.java:133) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.NotificationManager.notify(NotificationManager.java:104) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.example.test.MainActivity.onClick(MainActivity.java:55) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.view.View.performClick(View.java:2506) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.view.View$PerformClick.run(View.java:9112) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Handler.handleCallback(Handler.java:587) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Handler.dispatchMessage(Handler.java:92) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Looper.loop(Looper.java:130) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.ActivityThread.main(ActivityThread.java:3835) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at java.lang.reflect.Method.invokeNative(Native Method) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at java.lang.reflect.Method.invoke(Method.java:507) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 
12-15 19:30:27.838: E/AndroidRuntime(22020): at dalvik.system.NativeStart.main(Native Method) 
12-15 19:35:27.888: I/Process(22020): Sending signal. PID: 22020 SIG: 9 

我試試我的手機上使用Android版本2.3.7。任何幫助?

+3

從您的崩潰發佈logcat。另外,請確保'notification'不是'null'。 – codeMagic

回答

0

您應該將Intent傳遞給通知。