tink-crypto / tink

Tink is a multi-language, cross-platform, open source library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.
https://developers.google.com/tink
Apache License 2.0
13.5k stars 1.18k forks source link

android.content.SharedPreferences.edit()' on a null object reference #671

Closed denizbas92 closed 9 months ago

denizbas92 commented 1 year ago

In my application I am using EncryptedSharedPreferences. My application works every device that I have tried. However, there is happenning an error in some of devices that as shown in the title. By the way, I am creating EncryptedSharedPreferences after onCreate. My application worked in my Android 10 Xiamio devices.

What was the expected behavior?

I am expecting that EncryptedSharedPreferences can save some data to storage.

Do you have any debugging information?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'android.content.SharedPreferences$Editor android.content.SharedPreferences.edit()' on a null object reference at tr.com.dteknoloji.vwticari.datamanager.SharedPrefHelper.save(SharedPrefHelper.java:86) at tr.com.dteknoloji.vwticari.ui.intro.OnBoardingActivity.onClick(OnBoardingActivity.java:130)

Provide your version information:

juergw commented 1 year ago

Could you give some more details on where exactly the NullPointerException occurred?

LuisAngelPerezMoreno commented 1 year ago

I have the same problem.

juergw commented 1 year ago

Please give more details about the problem.

denizbas92 commented 1 year ago

This code block is inside a method. This method is triggered from an onClick method. I have no idea what it is going on. I am getting the error that has shown in the title. This code is working in my xamio redmi pro 8 but it is not working in some of devices.

Screen Shot 2023-02-14 at 16 14 08
juergw commented 1 year ago

It seems that the variable mSharedPreferences in EncryptedSharedPreferences.java is null, and that gets created with applicationContext.getSharedPreferences(fileName, Context.MODE_PRIVATE).

I don't know why that that would return null. So I can't help you with that error. Sorry.

juergw commented 9 months ago

If this is still an issue and you have a way to reproduce it or how to fix it, please open an issue on https://github.com/tink-crypto/tink-java.