정상적인 메서드에서 AsyncTask doInBackground 메서드로 일부 코드를 옮겼습니다. 파일 판독기를 제외한 모든 작업이 정상적으로 작동합니다. "상황을 해결할 수 없습니다"라는 메시지가 나타납니다. 나는 "context.getApplicationContext()"를 모두 사용하려고 시도했지만 "openFileInput (String) 메서드는 AlarmReceiver.backgroundputFTP 유형에 대해 정의되지 않았습니다."라는 메시지가 나타납니다. 누구 아이디어 야?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);
도우려고 주셔서 감사합니다,하지만 결과 – Kevmeister
@Kevmeister 그런 다음 "방법는 getContext()는 형 AlarmReceiver에 대한 정의이다"고, 당신의 AlarmReceiver의 필드 문맥 mContext을 정의, 당신의 putFTP에 mContext = 문맥을 , 먼저, 그리고 그 mContext.openFileInput AsyncTask에서 사용하십시오. –