You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AwesomeNotifications MediaPlayer样式未配NotificationButton触发报错

问题根因

使用AwesomeNotifications创建通知时,将布局设置为NotificationLayout.MediaPlayer样式但未配置至少一个NotificationButton,会触发空指针异常,报错堆栈如下:

java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationBuilder.setMediaPlayerLayout(NotificationBuilder.java:1064)
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationBuilder.setLayout(NotificationBuilder.java:836)
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationBuilder.getNotificationBuilderFromModel(NotificationBuilder.java:393)
[        ] V/MediaPlayer(21896): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
[        ] V/MediaPlayer(21896): cleanDrmObj: mDrmObj=null mDrmSessionId=null
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationBuilder.createNotification(NotificationBuilder.java:110)
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationSender.showNotification(NotificationSender.java:209)
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationSender.doInBackground(NotificationSender.java:128)
[        ] W/System.err(21896):     at me.carda.awesome_notifications.notifications.NotificationSender.doInBackground(NotificationSender.java:34)
[        ] W/System.err(21896):     at android.os.AsyncTask$3.call(AsyncTask.java:394)
[        ] W/System.err(21896):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[        ] W/System.err(21896):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
[        ] W/System.err(21896):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
[        ] W/System.err(21896):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
[        ] W/System.err(21896):     at java.lang.Thread.run(Thread.java:1013)

从堆栈定位可知,问题出在库内部的setMediaPlayerLayout方法:该方法直接调用按钮列表的size()方法获取按钮数量,没有对按钮列表做非空校验,当未配置按钮导致列表为null时就会触发空指针。

修复方案
  • 使用NotificationLayout.MediaPlayer布局时,必须为通知配置至少1个NotificationButton,常规媒体场景可配置播放/暂停、切歌这类标准控制按钮。
  • 若业务场景暂时不需要显示操作按钮,可添加一个无显示文案、无点击事件绑定的占位按钮,绕过空指针校验即可。

内容的提问来源于stack exchange,提问作者Suj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 02:45:48