1

我刚刚在我的项目中实现了 Pushbots 库。如果我的应用程序正在运行,推送通知效果很好。但是,如果应用程序没有运行,它总是会崩溃。我使用了 logcat,它说如下:

 09-26 02:40:28.143: E/AndroidRuntime(18464): FATAL EXCEPTION:       
 IntentService[GCMIntentService--1]
 09-26 02:40:28.143: E/AndroidRuntime(18464): java.lang.NullPointerException
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at   
 com.pushbots.push.Pushbots.regID(Pushbots.java:409)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at 
 com.pushbots.push.Pushbots.sendStatsToServer(Pushbots.java:282)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at 
 com.pushbots.push.GCMIntentService.onMessage(GCMIntentService.java:112)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at     com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:191)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at   
 android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at  
 android.os.Handler.dispatchMessage(Handler.java:99)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at    
 android.os.Looper.loop(Looper.java:137)
 09-26 02:40:28.143: E/AndroidRuntime(18464):   at   
 android.os.HandlerThread.run(HandlerThread.java:60)
 09-26 02:40:28.143: E/PowerManagerService(2116): WakeLock : binderDied()

如何修复此 NullPointerException?

4

1 回答 1

1

其实这是一个bug。

您可以通过创建单独的应用程序类来解决此问题。

package com.pusbots.androidpushbot;
import android.app.Application;
import com.pushbots.push.Pushbots;
public class SampleApplication extends Application {
private static final String SENDER_ID ="YOUR_SENDER_ID";
private static final String PUSHBOTS_APPLICATION_ID ="PUSHBOT_APP_ID";
    @Override 
   public void onCreate(){
        super.onCreate();
        Pushbots.init(this, SENDER_ID, PUSHBOTS_APPLICATION_ID);
    }
}

看这个视频教程:发送 GCM Android 推送通知

另请检查:pushbots-app-crash
app not running

于 2015-02-01T09:49:16.333 回答