Skip to content
DeveloperMemos

Attempt to invoke virtual method 'java.lang.String com.onesignal.language.LanguageContext.getLanguage()' on a null object reference

Android, OneSignal, Bug Fixing, Mobile Development1 min read

Hey there! I guess you ran into this error too? You're not alone. It has been causing me some headaches: "Attempt to invoke virtual method 'java.lang.String com.onesignal.language.LanguageContext.getLanguage()' on a null object reference." The sad news is that I don't have a solution at this point either, but you can read on for a couple more details.

What's Going On?

I think the OneSignal SDK might be trying to access a class that hasn't been initialized yet, and that's why the null pointer is getting thrown. The strange thing is, I didn't even update the SDK... I just removed another SDK from my project, released an update, and then started getting these errors.

So There's No Fix?

Not to my knowledge. I did a quick search about this and found one GitHub Issue, but there wasn't really anything written about a potential fix. It looks like the person who created the issue opted to try upgrading their version of OneSignal, and maybe that fixed things for them. I'm planning to do this myself in a future update. Unfortunately, I can't rollback this current update or freeze it because it contains some other important changes. If updating OneSignal doesn't work, I might have to reconsider using it. Thankfully, the percentage of users experiencing this crash isn't too high at this point. I might have to review my implementation of the SDK because I added it years ago, and the implementation might be outdated.

It's still kind of weird that I didn't touch anything related to OneSignal at all and started getting these crashes... Ah, the joys of Android Dev!