This might be the wrong way to go about this, so tell me if that’s the case:
I’m trying to use getFileStreamPath (which is derived from Context, as far as I understand) in another class, to separate some code from the main activity class. I’m doing this by passing the main activity’s context to the other class, and using that to invoke its methods.
In my main activity class:
LocalStorage lc = new LocalStorage(this);
Then, in the other class:
public class LocalStorage {
Context ctx;
public LocalStorage (Context c) {
c = ctx;
File lfile = ctx.getFileStreamPath("Activity.log");
....
But obviously I’m missing something, because running getFileStreamPath on the passed context in the LocalStorage class results in a NullPointerException.
You have your variables backwards.
should be
You’re assigning the uninitialized
Contextctxto the passed inContextc, so it will always be null.