【发布时间】:2014-02-26 06:12:54
【问题描述】:
我第一次使用内部存储,我的 openFileOutput 给了我一个错误。我不知道如何使这项工作,但如果 FileOutputStream 被删除,下面的方法工作得很好。谢谢!
public void Addition(View view) {
int num1 = numberone.getText().toString().trim().length();
int num2 = numbertwo.getText().toString().trim().length();
String numone = numberone.getText().toString();
String numtwo = numbertwo.getText().toString();
if(num1 == 0 || num2 == 0){
TextView value = (TextView)findViewById(R.id.answer);
value.setText("Numbers not entered");
}
else if(numone.equals("+") || numtwo.equals("+") || numtwo.equals("-") || numone.equals("-")){
TextView value = (TextView)findViewById(R.id.answer);
value.setText("Please enter numbers");
}
else{
answer = Float.parseFloat(numberone.getText().toString()) + Float.parseFloat(numbertwo.getText().toString());;
TextView value = (TextView)findViewById(R.id.answer);
value.setText("Your sum is " + answer);
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
}
}
【问题讨论】:
-
它无法识别 openFileOutput(FILENAME, Context.MODE_PRIVATE);它建议我添加一个 throw 声明或用 try/catch 包围。谢谢!
-
openFileOutput是ContextWrapper的函数。这个Addition函数声明在哪里? -
如何正确使用它来存储浮动“答案”?
-
如果它建议你用 try/catch 包围代码,那么就这样做。您还面临其他问题吗?
-
定义“不识别”。到目前为止提供的信息不足。
标签: java android storage internal internal-storage