我在安裝我的應用程序本身時得到以下NPE。請幫忙。UrbanAhiphip NPE
07-22 16:27:06.380: E/UA AP(6071): Unable to takeOff automatically
07-22 16:27:06.385: D/AndroidRuntime(6071): Shutting down VM
07-22 16:27:06.385: W/dalvikvm(6071): threadid=1: thread exiting with uncaught exception (group=0x415db2a0)
07-22 16:27:06.385: E/AndroidRuntime(6071): FATAL EXCEPTION: main
07-22 16:27:06.385: E/AndroidRuntime(6071): java.lang.RuntimeException: Unable to start receiver com.urbanairship.push.GCMPushReceiver: java.lang.NullPointerException
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2277)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.app.ActivityThread.access$1500(ActivityThread.java:140)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.os.Looper.loop(Looper.java:137)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-22 16:27:06.385: E/AndroidRuntime(6071): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 16:27:06.385: E/AndroidRuntime(6071): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 16:27:06.385: E/AndroidRuntime(6071): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-22 16:27:06.385: E/AndroidRuntime(6071): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-22 16:27:06.385: E/AndroidRuntime(6071): at dalvik.system.NativeStart.main(Native Method)
07-22 16:27:06.385: E/AndroidRuntime(6071): Caused by: java.lang.NullPointerException
07-22 16:27:06.385: E/AndroidRuntime(6071): at com.urbanairship.UAirship.getPackageName(Unknown Source)
07-22 16:27:06.385: E/AndroidRuntime(6071): at com.urbanairship.push.GCMPushReceiver.onReceive(Unknown Source)
07-22 16:27:06.385: E/AndroidRuntime(6071): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2270)
07-22 16:27:06.385: E/AndroidRuntime(6071): ... 10 more
即使我得到這個除了我能夠啓動應用程序。上運行:
url -X POST -u "<app id>:<mastersecret>" -H "Content-Type: application/json" --data '{"android": {"alert": "TestPushtoAPID"}, "apids": ["****4"]}' https://go.urbanairship.com/api/push/
我得到如下回應:
{
"push_id": "33e95250-f2b9-11e2-a8d0-14feb5d31f47"
}
儘管如此,我沒能看到我的設備上的任何通知。 MainActivity的
Part of Android Manifest
<!-- REQUIRED for Urban Airship GCM-->
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
部分:
UAirship.takeOff(this.getApplication(), options);
PushManager.enablePush();
PushManager.shared().setIntentReceiver(IntentReceiver.class);
String apid = PushManager.shared().getAPID();
你有什麼試過?你發現了什麼?空指針異常是因爲你正在使用的變量沒有在'無法啓動接收器com.urbanairship.push.GCMPushReceiver:java.lang.NullPointerException 07-22 16:27:06.385:E/AndroidRuntime(6071 ):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2277)'你有沒有在你的清單中聲明你的廣播接收器或者你是否實例化了它? – t0mm13b
請顯示確認的代碼。 – t0mm13b
OP:請停止在評論中張貼代碼,重新編輯您的問題,因爲這些評論使代碼無法閱讀。 – t0mm13b