2016-10-25 7 views
1

私のクラスでdoInBackgroundメソッドをオーバーライドできないのはなぜですか?doInBackgroundメソッド(asyncTask)をオーバーライドできません

public class AttemptLogin extends AsyncTask { 


@Override 

protected void onPreExecute() { 

    super.onPreExecute(); 

} 

@Override 

protected JSONObject doInBackground(String... args) { 



    String email = args[2]; 
    String password = args[1]; 
    String name= args[0]; 

    ArrayList params = new ArrayList(); 
    params.add(new BasicNameValuePair("username", name)); 
    params.add(new BasicNameValuePair("password", password)); 
    if(email.length()>0) 
     params.add(new BasicNameValuePair("email",email)); 

    JSONObject json = jsonParser.makeHttpRequest(URL, "POST", params); 


    return json; 

} 

protected void onPostExecute(JSONObject result) { 

    // dismiss the dialog once product deleted 
    //Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show(); 

    try { 
     if (result != null) { 
      Toast.makeText(getApplicationContext(),result.getString("message"),Toast.LENGTH_LONG).show(); 
     } else { 
      Toast.makeText(getApplicationContext(), "Unable to retrieve any data from server", Toast.LENGTH_LONG).show(); 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 


} 

} 

エラー: クラスAttemptLoginは、私は[オブジェクト(へdoInBackgroundのパラメータを変更した場合、それが動作AsyncTask '

「でdoInBackground(PARAMS ...)' 抽象宣言や抽象メソッドを実装する必要があります])。なぜ私は文字列の値を渡すことができないのですか?

+0

これら3つの偶然にオブジェクトためにあなたはAsyncTaskあなたの戻り値の型のクラスを伝える必要があり、この

public class AttemptLogin extends AsyncTask<String,Void,JSONObject> { ... 

ような何かにあなたのコード>'のものがあります重要なのです。 https://docs.oracle.com/javase/tutorial/java/generics/types.html – zapl

答えて

1
public class AttemptLogin extends AsyncTask<String, Void, JSONObject> {...} 
1

変更それ以外の場合、デフォルトは< `で

関連する問題