我有一個關於Android中的AsyncTask類的問題,以及它爲什麼給我一個錯誤。我已經定義了一個內部類在這裏..Android的AsyncTask錯誤與onPostExecute
class MyTask extends AsyncTask<String,String,Integer>{
Context context;
ProgressDialog dialog;
MyTask(Context c)
{
this.context = c;
}
//@Override
protected void onPreExecute()
{
dialog = new ProgressDialog(context);
dialog.setMessage("Scanning Ports!");
dialog.show();
}
@Override
protected Integer doInBackground(String... params) {
// TODO Auto-generated method stub
for(intBeg = intBeg; intBeg <= intEnd; intBeg++
{
try
{
Socket s = new Socket(strMachine, intBeg);
isConnected += strMachine + " Is Listening On Port: " + intBeg + "\n";
Log.d("PORTSCAN", isConnected);
s.close();
}catch(Exception e){
notConnected += strMachine + " Is Not Listening On Port: " + intBeg + "\n";
//Toast.makeText(getBaseContext(), e.getMessage(), 3000).show();
Log.d("PORTSCAN", notConnected);
}
}
return 1;
}
protected void onPostExecute(Integer... params)
{
}
protected void onProgressUpdate(String... params)
{
}
}
然而,當doInBackground完成後,它應該調用onPostExecute(),它永遠不會發生。即使當我嘗試在onPostExecute()上使用「@Override」註釋時,它也會給我一個錯誤,說明onPostExecute必須重載超類方法。我沒有得到正在發生的事情!任何幫助?謝謝!
確保您已導入正確的類,它是, android.os.AsyncTask –
jeet