tink-crypto/tink

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

denizbas92 opened this issue · 6 comments

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:

  • Language: Java
  • Version: java 19
  • Environment: Android 8.1

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

I have the same problem.

Please give more details about the problem.

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

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.

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.