2012-12-05 85 views
0

我有點新至Android編程和不能似乎動搖了這個bug ..的AsyncTask混亂抽象

它告訴我:

The type LoginForm.login must implement the inherited abstract method AsyncTask<String,Void,String>.doInBackground(String...) 

這是代碼:

private class login extends AsyncTask<String, Void, String> { 

    protected String doInBackground(String url) { 
     String response = ""; 
      DefaultHttpClient client = new DefaultHttpClient(); 
      HttpGet httpGet = new HttpGet(url); 
      try { 
      HttpResponse execute = client.execute(httpGet); 
      InputStream content = execute.getEntity().getContent(); 

      BufferedReader buffer = new BufferedReader(new InputStreamReader(content)); 
      String s = ""; 
      while ((s = buffer.readLine()) != null) { 
       response += s; 
      } 

      } catch (Exception e) { 
      e.printStackTrace(); 
      } 
     return response; 
     } 

     @Override 
     protected void onPostExecute(String result) { 

     int mId = 0; 

     //Close loading bar and text 
     login_form_loader.setVisibility(View.INVISIBLE); 
     warning.setText(result); 

     } 
    } 

這是什麼意思,我該如何解決這個問題?

回答

3

您需要方法的簽名更改爲:

protected String doInBackground(String... url) 

(你應該對方法中添加註釋@Override也爲清楚起見)。

+0

這偉大工程,但現在我得到的錯誤:構造HTTPGET(字符串[])未定義 – MichaelH

+1

假設你只能傳遞一個字符串/只對第一個字符串感興趣,可以使用'new HttpGet(url [0]);' – assylias

0

的doinbackground功能應該是這樣的,你的情況

@Override 
    protected Result doInBackground(String... params) { 
     // TODO Your code here 
     return null; 
    }