Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method invocation 'onPostRequest' may produce 'java.lang.NullPointerException' #296

Closed
suswari opened this issue Feb 28, 2019 · 6 comments · Fixed by #349
Closed

Method invocation 'onPostRequest' may produce 'java.lang.NullPointerException' #296

suswari opened this issue Feb 28, 2019 · 6 comments · Fixed by #349

Comments

@suswari
Copy link

suswari commented Feb 28, 2019

Hi,
I am trying to get a local notification on Android and I see the below error when I run the device:

D/ReactNativeNotifs: Native method invocation: postLocalNotification
E/unknown:ReactNative: Exception in native call
java.lang.NullPointerException: Attempt to invoke interface method 'int com.wix.reactnativenotifications.core.notification.IPushNotification.onPostRequest(java.lang.Integer)' on a null object reference
at com.wix.reactnativenotifications.RNNotificationsModule.postLocalNotification(RNNotificationsModule.java:102)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:751)
.
.
Any idea, what could have been wrong?

notificationservice.js:

/*

*/
import {NotificationsAndroid} from 'react-native-notifications';

const postNotification = () => {
let localNotification = NotificationsAndroid.localNotification({
body: "My first notification",
title: "test title",
});
};

module.exports = postNotification;

@ywongweb
Copy link

ywongweb commented Mar 2, 2019

Same problem here
"react-native-notifications": "1.2.52",

edit:
I think I found the cause. In the lib's PushNotification.java, the verifyNotificationBundle check is looking for a google.message_id key that doesn't seem to exist in a local notification. If you change the method to always returns true, the local notification will work.

    private static boolean verifyNotificationBundle(Bundle bundle) {
        if (bundle.getString("google.message_id") != null) {
            return true;
        }

        return false;
    }

Not sure why we are checking for a google message ID for local notification, maybe @yogevbd can shed some light on this. Or did we missed a setup step?

@nickelbob
Copy link

Any news on this? I'm also experiencing it. Thanks!

@bradser
Copy link

bradser commented Mar 13, 2019

I worked around it by passing in an empty string for the 'google.message_id' value when calling localNotification(). I didn't try running instead against #71, but I would hope that would resolve the issue.

@sstano
Copy link

sstano commented Mar 21, 2019

I worked around it by passing in an empty string for the 'google.message_id' value when calling localNotification(). I didn't try running instead against #71, but I would hope that would resolve the issue.

Great, thanks! Works for me!

NotificationsAndroid.localNotification({
    "title": "Local notification",
    "body": "This notification was generated by the app!",
    "extra": "data",
    "google.message_id": "" // <-- Adding this line fixed the problem
});

@wlaurance
Copy link

Add the google.message_id worked for me as well. 🤷‍♂

@MewX
Copy link

MewX commented Jul 22, 2019

Has anyone tried iOS yet? Is this on iOS as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants