简体   繁体   English

“无法解析方法'openFileOutput(Java.lang.String,int)'”

[英]“Cannot resolve method 'openFileOutput(Java.lang.String, int)'”

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)'" 但是在openFileOutput上我收到错误“无法解析方法'openFileOutput(Java.lang.String,int)'”

How can I fix it? 我该如何解决?

Use ctx to access openFileOutput method in noraml class which is not extending any subclass of Context class: 使用ctx访问noraml类中的openFileOutput方法,该方法不扩展Context类的任何子类:

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

Because openFileOutput is define in Context class 因为openFileOutput是在Context类中定义的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法解析方法'openFileOutput(java.lang.String,int) - Cannot resolve method 'openFileOutput(java.lang.String,int) 如何修复无法解析方法'openFileOutput(java.lang.String,int)' - How to fix Cannot resolve method 'openFileOutput(java.lang.String, int)' How to solve this error “cannot resolve method 'addData(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)'”? - How to solve this error “cannot resolve method 'addData(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)'”? 无法解析方法put(java.lang.string,java.lang.string) - Cannot resolve method put(java.lang.string, java.lang.string) 无法解析方法“ List.of(java.lang.String,java.lang.String)” - Cannot resolve method 'List.of(java.lang.String, java.lang.String)' 无法解析方法“get(java.lang.String)” - Cannot resolve method 'get(java.lang.String)' 无法解析方法“setText(java.lang.String[])” - Cannot resolve method 'setText(java.lang.String[])' Android:无法解析方法“ query(java.lang.string)” - Android: cannot resolve method “query(java.lang.string)” 无法解析方法'displayMessage(java.lang.String)' - Cannot resolve method 'displayMessage(java.lang.String)' 无法解析方法'setTitle(java.lang.String)' android studio - Cannot resolve method 'setTitle(java.lang.String)' android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM