本文介绍了GCM更新7.5至8.3.0致命异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的Gradle项目中更新GCM服务(Google云消息)库(从7.5到8.3.0)。
但现在,使用这个新版本,我无法启动之前完美工作的以前的活动。



处理以下错误的代码是:

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


$ b

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);
}

返回的错误:

  FATAL EXCEPTION:AsyncTask#1 
java.lang.NullPointerException:尝试在空对象引用上调用虚方法'int java.lang.String.hashCode()'
E / AndroidRuntime:在com.google.android.gms.gcm.GcmListenerService.zzo(未知来源)
E / AndroidRuntime:在com.google.android.gms.gcm.GcmListenerService.zza(未知源)
E / AndroidRuntime:在com.google.android.gms.gcm.GcmListenerService $ 1.run(未知源)
E / AndroidRuntime:在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。 java:1112)
E / AndroidRuntime:在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)
E / AndroidRuntime:at java.lang.Thread.run(Thread。 java:818)

Gradle文件:

 依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
编译'com.android.support:appcompat-v7:21.0.3'
编译'com.google.android.gms:play-services-gcm:8.3.0'
}

如果我回滚到之前的GCM版本(7.5),它会按预期恢复。
你知道什么改变了吗?我检查了更新日志,但我无法找到任何有关它的信息。



感谢您的帮助 解决方案

尝试查看反编译使用您的IDE的 GcmListenerService 类文件。当我使用Android Studio for 8.3.0来执行此操作时,似乎抛出异常的代码正试图从调用该服务的意图中获取ACTION。



我想知道为什么要调用的子类GcmListenerService 明确吗?消息接收的正常GCM处理是将消息传递给 GcmReceiver ,然后将消息传递给应用程序的 GcmListenerService 进行处理。你不应该明确地调用你的监听器服务, GcmReceiver 就是这样做的。看一看。


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

解决方案

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.

这篇关于GCM更新7.5至8.3.0致命异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 14:14
查看更多