I have a little issue with writing a file in Internal Storage in Android. I’m trying to do it from a helper class which is not an activity. Here is the code I’m using :
FileOutputStream fos = context.openFileOutput("media", context.MODE_PRIVATE);
fos.write(media.getBytes());
fos.close();
And it throws me a null pointer exception at the first line. I tried with this.context.openFileOutput("media",this.context.MODE_PRIVATE); & this.context.openFileOutput("media",Context.MODE_PRIVATE); but nothing helps.
Any idea how to solve that issue?
Actually I had the same issue and here is the solution :
You can use this :
Activity1.java
helperClass.java
Hope this helps!