Search code examples
androidcordovapushwooshcrosswalk-runtime

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


I'm trying to run a Apache Cordova based app with the PushWoosh plugin on Android. To avoid fragmentation problems on Android, we're using MobileChromeApps to build our Android version of the app. However, I can't register the device for push messages via PushWoosh. The code is working flawlessly on iOS.

The error happens as soon as I run plugins.pushNotification.registerDevice.

This is what adb logcat gives me:

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). 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

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.


Solution

  • It looks like you didn't provide credentials for push notifications. It should be either in your AndroidManifest.xml

    Look step 4 here: 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