当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to fix android error "method openFileInput in class Context cannot be applied to given types;2

问题描述:

Within my MainActivity.java I am trying to open a file according to the code given here. But when running the code

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

final Button button = (Button) findViewById(R.id.btn1);

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

Toast.makeText(getBaseContext(), "YOUR TEXT HERE", Toast.LENGTH_LONG).show();

// Perform action on click

FileInputStream fis = getBaseContext().openFileInput("hello.txt", Context.MODE_PRIVATE);

InputStreamReader isr = new InputStreamReader(fis);

BufferedReader bufferedReader = new BufferedReader(isr);

StringBuilder sb = new StringBuilder();

String line;

while ((line = bufferedReader.readLine()) != null) {

sb.append(line);

}

}

});

}

}

I get the following error:

Error:(27, 55) error: method openFileInput in class Context cannot be applied to given types;

required: String

found: String,int

reason: actual and formal argument lists differ in length

I am not even able to understand what the error means. What 'argument list' is the message referring to?

分享给朋友:
您可能感兴趣的文章:
随机阅读: