gpt4 book ai didi

android - 通知管理器错误

转载 作者:行者123 更新时间:2023-11-30 01:43:29 24 4
gpt4 key购买 nike

//with context my code is not working
private void Notify(String notificationTitle,String notificationMesage){
NotificationManager notificationManager=/8*(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);//li//ne75
NotificationCompat.Builder mBuiler=(NotificationCompat.Builder)new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.small_logo)
.setContentTitle("WOBOT")
.setContentText("Overdue Task\n")
.setSubText("Task:a/c,\nGhaziabad\n,RS.200")
.addAction(R.drawable.ic_done, "Accept", null)
.addAction(R.drawable.ic_clear, "Decline", null)
.setDefaults(Notification.DEFAULT_SOUND)
.setDefaults(Notification.DEFAULT_VIBRATE);

Notification notify=mBuiler.getNotification();


myNotification=mBuiler.getNotification();
notificationManager.notify(23,notify);


}

生成以下错误:

java.lang.NullPointerException
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at com.example.acer.wobot_sample.Fragment_one.Notify(Fragment_one.java:75)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at com.example.acer.wobot_sample.Fragment_one.onClick(Fragment_one.java:67)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.view.View.performClick(View.java:4463)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18770)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:808)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:103)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.os.Looper.loop(Looper.java:193)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5333)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
12-04 18:58:09.005 16329-16329/com.example.acer.wobot_sample E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)

最佳答案

在 fragment 中,您可以使用 getActivity() 方法获取上下文。

关于android - 通知管理器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34089554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com