我在我的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