Reputation: 523
I'm getting a 'cannot resolve method' error with the line of code:
FileInputStream fis = openFileInput(fileName);
I'm not in an acitivty I'm in a seperate class so I'm assuming that's why it won't work. I've tried doing things like this but they still give me the 'cannot resolve method error:
FileInputStream fis = getApplicationContext.openFileInput(fileName);
Thanks for any help, I'm new to android development
Upvotes: 5
Views: 7488
Reputation: 668
Main error is due to Context please give the right context or you can pass context by using it in function. for this you will need to pass Activity Context to it by sending Context using parametrized method as:
protected void onCreate(String filename,Context context) {
try
{
FileInputStream fis = context.openFileInput(filename);
//...your code here...
}
catch (Exception ex)
{
}
}
Upvotes: 1
Reputation: 2136
I had a similar case of this, where I couldn't use openFileInput
or openFileOutput
while in a class that wasn't an activity. In my case, though, I was already passing the context to the method, so I just did
context.openFileInput("stuff.dat");
If you're able to do something similar, that solves it.
Upvotes: 11