i have a question regarding the AsyncTask class in android, and why it is giving me an error. I have defined an inner class here..
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)
{
}
}
However, when the doInBackground finishes, it supposed to call onPostExecute(), which never happens. And even when i try to use the “@Override” annotation over the onPostExecute(), it gives me an error saying onPostExecute must override a superclass method. I dont get what is happening! any help? Thanks!
onPostExcecute(Integer result)takes a single argument (no …).If the arguments don’t match, it will not match the super method and will therefore not override it (and be called). Generally if
@Overridegives you an error something is wrong with your method name/parameters (or the superclass does not have such a method).