简体   繁体   English

Android上的PushWoosh:运行.registerDevice()时,出现“ nullpointerexception”

[英]PushWoosh on Android: `nullpointerexception` when running .registerDevice()

I'm trying to run a Apache Cordova based app with the PushWoosh plugin on Android. 我正在尝试在Android上使用PushWoosh插件运行基于Apache Cordova的应用程序 To avoid fragmentation problems on Android, we're using MobileChromeApps to build our Android version of the app. 为了避免Android上出现碎片问题,我们使用MobileChromeApps构建我们的Android版本的应用程序。 However, I can't register the device for push messages via PushWoosh. 但是,我无法通过PushWoosh将设备注册为推送消息。 The code is working flawlessly on iOS. 该代码可在iOS上完美运行。

The error happens as soon as I run plugins.pushNotification.registerDevice . 一旦运行plugins.pushNotification.registerDevice ,就会发生该错误。

This is what adb logcat gives me: 这是adb logcat给我的:

D/PushNotifications(17915): Plugin Called
W/System.err(17915): java.lang.NullPointerException
W/System.err(17915):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.internalRegister(PushNotifications.java:189)
W/System.err(17915):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.execute(PushNotifications.java:390)
W/System.err(17915):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:82)
W/System.err(17915):    at org.apache.cordova.PluginManager.exec(PluginManager.java:128)
W/System.err(17915):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:63)
W/System.err(17915):    at org.apache.cordova.engine.crosswalk.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err(17915):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(17915):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
W/System.err(17915):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(17915):    at android.os.Looper.loop(Looper.java:137)
W/System.err(17915):    at android.os.HandlerThread.run(HandlerThread.java:60)

It looks like the Java code fails somehow - but why and how, I don't know (web developer by heart, I don't know Java). 看来Java代码以某种方式失败了-但是我不知道为什么以及为什么(本质上是Web开发人员,我也不了解Java)。 The app never calls any remote resources, so the error must be somewhere in the app setup. 该应用程序永远不会调用任何远程资源,因此该错误必须在应用程序设置中。

Any ideas? 有任何想法吗? All help is appreciated (and might even be rewarded with a beer if you're in Copenhagen). 感谢您的所有帮助(如果您在哥本哈根,甚至可以得到啤酒来回报)。

EDIT: A more detailed look at adb logcat -s System.err reveals that the initialization fails as well, probably resulting in the other error 编辑:对adb logcat -s System.err更详细研究揭示了初始化也失败,可能导致另一个错误

W/System.err( 7439): org.json.JSONException: No value for projectid
W/System.err( 7439):    at org.json.JSONObject.get(JSONObject.java:354)
W/System.err( 7439):    at org.json.JSONObject.getString(JSONObject.java:510)
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.initialize(PushNotifications.java:174)
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.execute(PushNotifications.java:384)
W/System.err( 7439):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:82)
W/System.err( 7439):    at org.apache.cordova.PluginManager.exec(PluginManager.java:128)
W/System.err( 7439):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:63)
W/System.err( 7439):    at org.apache.cordova.engine.crosswalk.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
W/System.err( 7439):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 7439):    at android.os.Looper.loop(Looper.java:137)
W/System.err( 7439):    at android.os.HandlerThread.run(HandlerThread.java:60)
W/System.err( 7439): java.lang.NullPointerException
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.internalRegister(PushNotifications.java:190)
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.execute(PushNotifications.java:393)
W/System.err( 7439):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:82)
W/System.err( 7439):    at org.apache.cordova.PluginManager.exec(PluginManager.java:128)
W/System.err( 7439):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:63)
W/System.err( 7439):    at org.apache.cordova.engine.crosswalk.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
W/System.err( 7439):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 7439):    at android.os.Looper.loop(Looper.java:137)
W/System.err( 7439):    at android.os.HandlerThread.run(HandlerThread.java:60)
W/System.err( 7439): java.lang.NullPointerException
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.internalRegister(PushNotifications.java:190)
W/System.err( 7439):    at com.pushwoosh.plugin.pushnotifications.PushNotifications.execute(PushNotifications.java:393)
W/System.err( 7439):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:82)
W/System.err( 7439):    at org.apache.cordova.PluginManager.exec(PluginManager.java:128)
W/System.err( 7439):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:63)
W/System.err( 7439):    at org.apache.cordova.engine.crosswalk.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 7439):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:28)
W/System.err( 7439):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 7439):    at android.os.Looper.loop(Looper.java:137)
W/System.err( 7439):    at android.os.HandlerThread.run(HandlerThread.java:60)

Thank you so much! 非常感谢!

Github issue here . Github问题在这里

It looks like you didn't provide credentials for push notifications. 您似乎没有提供推送通知的凭据。 It should be either in your AndroidManifest.xml 它应该在您的AndroidManifest.xml中

Look step 4 here: https://www.pushwoosh.com/programming-push-notification/android/native-android-sdk-integration/ 在这里查看第4步: https//www.pushwoosh.com/programming-push-notification/android/native-android-sdk-integration/

Or in onDeviceReady function, see here: https://github.com/Pushwoosh/phonegap-3-sample-app/blob/master/www/js/PushwooshAndroid.js 或在onDeviceReady函数中,请参见此处: https : //github.com/Pushwoosh/phonegap-3-sample-app/blob/master/www/js/PushwooshAndroid.js

(Starting with an answer, because I don't have enough reputation to comment) (从一个答案开始,因为我没有足够的声誉来发表评论)

Are you testing push notifications on a simulator? 您是否正在模拟器上测试推送通知? (you mentioned "test device" in the Github issue, so just confirming) (您在Github问题中提到了“测试设备”,因此请确认一下)

I ask, because the simulator is not able neither to subscribe nor receive push notifications. 我问,因为模拟器既不能订阅也不能接收推送通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM