我在我的AsyncTask中有一个错误。我试图用FileOutputStream保存数据到一个文件,因为我需要这个数据永久。Android的AsyncTask使用openFileOutputStream
所以IAM阅读本教程:Tutorial
但如果IAM将代码添加到我的AsyncTask我得到这个错误:
“的方法openFileOutputStream(字符串,整数)是未定义的类型 MainActivity。 DownloadSpielplan”
DownloadSpielplan是我的AsyncTask
private class DownloadSpielplan extends AsyncTask <Void, Void, String>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
//dont wonder reverseString is created and filled i delete this part from the code for more readability
FILENAME = "SpielTag";
JOUR = reverseString;
FileOutputStream fos = openFileOutputStream(FILENAME, Context.MODE_PRIVATE);
fos.write(JOUR.getBytes());
fos.close();
return reverseString;
}
@Override
protected void onPostExecute(String reverseString) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Download abgeschlossen!", Toast.LENGTH_LONG).show();
super.onPostExecute(reverseString);
}
}
我猜问题是,iam从AsyncTask调用openFileOutputStream,但我无法找到解决方案如何解决它。 (IAM原因Android中真的新)
把你logcat错误。 – Hemant
它不是一个logcat错误,它的错误eclipse告诉我,在这一行:FileOutputStream fos = openFileOutputStream(FILENAME,Context.MODE_PRIVATE); eclipse告诉我:“方法openFileOutputStream(String,int)对于MainActivity.DownloadSpielplan类型” – user1662203
“未定义,您必须调用openFileOutput,则必须使用活动上下文调用此方法。 http://goo.gl/UWhN1m – rajpara