Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                    
                
        

我第一次使用内部存储,而我的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);

    }

}

最佳答案

如果您的类没有扩展Context子类,则需要传递一个Context实例(一个Activity,一个Service,一个etc)来调用openFileInput。
另外,您还需要捕获java.io.FileNotFoundException或向您的方法添加throws声明。

希望能帮助到你。

10-08 15:01
查看更多