Android.app.Notification.extras null

安稳与你 提交于 2019-12-13 18:15:13

问题


So I am confused and I don't know how to fix the error crashlytics and google playstore keep saying my users are having. Here is my code:

if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            Notification notification = (Notification) event.getParcelableData();

String text = "";

if (notification.extras.getString(Notification.EXTRA_TEXT) != null){
                    text  = notification.extras.getString(Notification.EXTRA_TEXT);
                }

if (text != null) {
    if (text.equals("You have been idle, would you like to stay online?")
      startApp();
{

But crashlytics and google playstore say that I am referencing null Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'android.os.Bundle android.app.Notification.extras' on a null object reference, how is this possible when I am checking for null first? Here is the full error code:

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'android.os.Bundle android.app.Notification.extras' on a null object reference
   at com.gonow.services.AutoService.onAccessibilityEvent(Unknown Source)
   at android.accessibilityservice.AccessibilityService$2.onAccessibilityEvent(AccessibilityService.java:1472)
   at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1608)
   at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6823)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)

I have already looked at this: What is a NullPointerException, and how do I fix it?

来源:https://stackoverflow.com/questions/48363062/android-app-notification-extras-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!