GCM update 7.5 to 8.3.0 fatal exception

走远了吗. 提交于 2020-01-14 14:06:47

问题


I tried to update the GCM services (Google cloud messages) libraries (from 7.5 to 8.3.0) in my Gradle project. But now, with this new version, i'm unable to launch my previous activity which was working perfectly before.

The code which handle the following error is :

Intent in = new Intent(this, MyGcmListenerService.class);
startService(in);

MyGcmListenerService.java :

public class MyGcmListenerService extends GcmListenerService
{
    private static final String TAG = "MyGcmListenerService";

    @Override
    public void onMessageReceived(String from, Bundle data)
    {
        Log.w(TAG, "onMessageReceived");
    }

The returned error :

FATAL EXCEPTION: AsyncTask #1
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
E/AndroidRuntime:     at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
E/AndroidRuntime:     at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
E/AndroidRuntime:     at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818)

Gradle files :

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
}

If I rollback to the previous GCM version (7.5) it's working back as expected. Do you know what changed ? I checked the changelogs but I'm unable to found any informations about it. https://developers.google.com/android/guides/releases

Thank you for your help


回答1:


Try looking at the decompiled class file for GcmListenerService using your IDE. When I do that with Android Studio for version 8.3.0, the code that appears to be throwing the exception is attempting to get the ACTION from the intent that invoked the service. Because you are invoking the service with an explicit intent, the ACTION is null.

I'm wondering why you are invoking your subclass of GcmListenerService explicitly? The normal GCM processing for message receipt is for the message to be delivered to GcmReceiver, which then passes it to the app's instance of GcmListenerService for processing. You should not be invoking your listener service explicitly, GcmReceiver does that. Take a look at the sample project.



来源:https://stackoverflow.com/questions/33692070/gcm-update-7-5-to-8-3-0-fatal-exception

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