我将一些代码从普通方法移到了AsyncTask doInBackground方法中,除filereader之外,一切正常。我得到“上下文无法解决”。 我试着把“context.getApplicationContext()”放在一起,但这只是让我“类型AlarmReceiver.backgroundputFTP的方法openFileInput(字符串)未定义”。任何人的想法请好吗?AsyncTask中的FileInputStream错误
public void putFTP(Context context)
{
new backgroundputFTP().execute();
}
private class backgroundputFTP extends AsyncTask< Void, Void,Void >
{
@Override
protected Void doInBackground(Void... params)
{
//
// Push query result text file to FTP server
//
FTPClient client = new FTPClient();
FileInputStream fis = null;
Looper.prepare();
try {
client.connect(ipAddress);
client.enterLocalPassiveMode();
client.login(user, pass);
//
// Create an InputStream of the file to be uploaded
//
filename = "sdcardstats.txt";
fis = context.getApplicationContext().openFileInput(filename);
感谢试图帮助,但结果“的方法的getContext()是未定义的类型AlarmReceiver” – Kevmeister
@Kevmeister然后,定义在AlarmReceiver现场上下文mContext,做mContext =上下文您putFTP ,首先,然后使用AsyncTask中的mContext.openFileInput –