I’m creating a file for internal storage, and I’m running into a problem when the data is written. I know that it retrieves the right data when it’s called (I used a Logcat tag to check that it was), but as soon as it tries to open the FileOutputStream, it says that there is a NullPointerException on the second line:
static ContextWrapper wrap = new ContextWrapper(context);
FileOutputStream gamesave = wrap.openFileOutput (FILENAME, Context.MODE_PRIVATE);
gamesave.write(DATA.getBytes());
gamesave.close();
I’ve looked at other questions and I can’t figure out why the NullPointerException is there, it seems to be following the right procedure.
I think you have the wrong Context in your
contextvar (i.e. ApplicationContext). Try using the context directly – without the Wrapper.