openFileOutput未定义类型

时间:2014-02-03 12:46:43

标签: android

我正在关注一个教程,在openFileOutput中有一个建议用try catch包围它。但在我的代码中,它只建议创建方法openFileOutput(String, int)。我正在使用fragment btw。这是我的代码:

public class Tab1 extends Fragment implements OnClickListener { 

    TextView text_fname, text_lname;
    EditText edit_fname, edit_lname;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {    

        View v = inflater.inflate(R.layout.tab1, container, false);

        text_fname = (TextView) v.findViewById(R.id.text1);
        text_lname = (TextView) v.findViewById(R.id.text2);

        edit_fname = (EditText) v.findViewById(R.id.edit1);
        edit_lname = (EditText) v.findViewById(R.id.edit2);

        Button button = (Button) v.findViewById(R.id.button1);
        button.setOnClickListener(this);

        return v;
    }

    @Override
    public void onClick(View arg0) {

        String fname1 = text_fname.getText().toString();
        String fname2 = edit_fname.getText().toString();

        String lname1 = text_lname.getText().toString();
        String lname2 = edit_lname.getText().toString();    

        FileOutputStream fos=openFileOutput("test.txt", Context.MODE_PRIVATE);

    }

}

1 个答案:

答案 0 :(得分:0)

将该行更改为以下内容:

FileOutputStream fos = getActivity().openFileOutput("test.txt", Context.MODE_PRIVATE);
相关问题