android 通知生成期间Java中出现空指针异常[已关闭]

x7yiwoj4  于 2023-02-17  发布在  Android
关注(0)|答案(1)|浏览(129)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
2天前关闭。
Improve this question

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.notificationsample, PID: 5456
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notificationsample/com.example.notificationsample.MainActivity}: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=new channel shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=new channel shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
        at android.app.NotificationManager.fixNotification(NotificationManager.java:700)
        at android.app.NotificationManager.notifyAsUser(NotificationManager.java:679)
        at android.app.NotificationManager.notify(NotificationManager.java:628)
        at android.app.NotificationManager.notify(NotificationManager.java:604)
        at com.example.notificationsample.MainActivity.onCreate(MainActivity.java:30)
        at android.app.Activity.performCreate(Activity.java:8305)
        at android.app.Activity.performCreate(Activity.java:8284)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7872) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
W/System: A resource failed to call close.

有没有人能解释一下这里的错误。。谢谢。

58wvjzkj

58wvjzkj1#

根据您的日志,我认为您没有指定或输入无效的通知小图标路径。

(Caused by: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=new channel shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE))

请查看与NotificationCompact(https://developer.android.com/reference/androidx/core/app/NotificationCompat)相关的Android开发人员文档
并为您的下一个答案给予一个更好的格式,例如,如果您向我们展示您的通知的构建器,我们可能会帮助您更多。

相关问题