Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot resolve method 'openFileOutput(Java.lang.String, int)'"

Tags:

java

android

io

I'm creating a class with some Read/Write from file functions.

String FILENAME = "my_file";
FileOutputStream fos;

public void write(String text, Context ctx)
{
    fos = openFileOutput(FILENAME, ctx.MODE_PRIVATE);
    try {
        fos.write(text.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

But on openFileOutput I get the error "Cannot resolve method 'openFileOutput(Java.lang.String, int)'"

How can I fix it?

like image 775
Philip Avatar asked Sep 21 '26 15:09

Philip


1 Answers

Use ctx to access openFileOutput method in noraml class which is not extending any subclass of Context class:

fos = ctx.openFileOutput(FILENAME, ctx.MODE_PRIVATE);

Because openFileOutput is define in Context class

like image 129
ρяσѕρєя K Avatar answered Sep 27 '26 16:09

ρяσѕρєя K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!