UrbanAirship NPE [英] UrbanAirship NPE

查看:267
本文介绍了UrbanAirship NPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下NPE在安装我的应用程序本身。请帮助。

  07-22 16:27:06.380:E / UA AP(6071):无法自动腾飞
07-22 16:27:06.385:D / AndroidRuntime(6071):关闭VM
07-22 16:27:06.385:W / dalvikvm(6071):主题ID = 1:螺纹未捕获的异常(组= 0x415db2a0)退出
07-22 16:27:06.385:E / AndroidRuntime(6071):致命异常:主要
07-22 16:27:06.385:E / AndroidRuntime(6071):了java.lang.RuntimeException:无法启动接收com.urbanairship.push.GCMPushReceiver:显示java.lang.NullPointerException
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2277)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.app.ActivityThread.access $ 1500(ActivityThread.java:140)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.os.Handler.dispatchMessage(Handler.java:99)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.os.Looper.loop(Looper.java:137)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.app.ActivityThread.main(ActivityThread.java:4898)
07-22 16:27:06.385:E / AndroidRuntime(6071):在java.lang.reflect.Method.invokeNative(本机方法)
07-22 16:27:06.385:E / AndroidRuntime(6071):在java.lang.reflect.Method.invoke(Method.java:511)
07-22 16:27:06.385:E / AndroidRuntime(6071):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-22 16:27:06.385:E / AndroidRuntime(6071):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-22 16:27:06.385:E / AndroidRuntime(6071):在dalvik.system.NativeStart.main(本机方法)
07-22 16:27:06.385:E / AndroidRuntime(6071):因:显示java.lang.NullPointerException
07-22 16:27:06.385:E / AndroidRuntime(6071):在com.urbanairship.UAirship.getPackageName(来源不明)
07-22 16:27:06.385:E / AndroidRuntime(6071):在com.urbanairship.push.GCMPushReceiver.onReceive(来源不明)
07-22 16:27:06.385:E / AndroidRuntime(6071):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2270)
07-22 16:27:06.385:E / AndroidRuntime(6071):10 ...更多

虽然我得到这个除外我可以启动应用程序。上运行:

  URL -X POST -u<应用程序ID>:< mastersecret>中-H内容类型:应用程序/ JSON--data{机器人:{警告:TestPushtoAPID},apids:**** 4]}的https://去.urbanairship.com / API /推/

我收到以下响应:

  {
    push_id:33e95250-f2b9-11e2-a8d0-14feb5d31f47
}

在尽管如此,我无法看到我的设备上的任何通知。

  Android清单的一部分
<! - 需要城市飞艇GCM - >
<接收机器人:名字=com.urbanairship.CoreReceiver/>
<接收机器人:名字=com.urbanairship.push.GCMPushReceiver机器人:权限=com.google.android.c2dm.permission.SEND>
    &所述;意图滤光器>
        <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
        <作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>
    &所述; /意图滤光器>
< /接收器>

MainActivity的部分:

  UAirship.takeOff(this.getApplication(),选件);
PushManager.enablePush();
PushManager.shared()setIntentReceiver(IntentReceiver.class)。
字符串APID = PushManager.shared()getAPID()。


解决方案

其实这个问题是实现图书馆的正确。

起飞以及其他配置code应该在的OnCreate 的<一个HREF =htt​​p://developer.android.com/reference/android/app/Application.html相对=nofollow> 应用 类,这是用于维护的全局状态的应用的。这是我们大多数人去wrong.We把它放在前台活动取值的OnCreate

接下来,您需要提及的全名的的应用您正在使用的 AndroidManifest类。 XML 应用程序标签中是这样的:

 &lt;应用
        机器人:名字=com.popa.app.MyApplication
        ..

是如何被实现为的 原UA的文档

I am getting the following NPE while installing my app itself. Please help.

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

Even though I get this excepting I am able to start the app. On running :

url -X POST -u "<app id>:<mastersecret>" -H "Content-Type: application/json" --data '{"android": {"alert": "TestPushtoAPID"}, "apids": ["****4"]}' https://go.urbanairship.com/api/push/

I am getting the following response :

{
    "push_id": "33e95250-f2b9-11e2-a8d0-14feb5d31f47"
}

In spite of this, I am not able to see any notification on my device.

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>

Part of MainActivity:

UAirship.takeOff(this.getApplication(), options); 
PushManager.enablePush(); 
PushManager.shared().setIntentReceiver(IntentReceiver.class); 
String apid = PushManager.shared().getAPID();

解决方案

Actually the problem was in implementation of the library correctly.

The takeOff as well as the other configuration code should be in the OnCreate of the Application class which is used for maintaining global state of the application.This is where most of us go wrong.We put it in the foreground Activitys OnCreate.

Next you need to mention the fully qualified name of the Application class which you are using in the AndroidManifest.xml within your application tag this way:

 <application
        android:name="com.popa.app.MyApplication"
        ..

This is how it is to be implemented as mentioned in the original docs of UA.

这篇关于UrbanAirship NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆