2013-11-22 54 views
0

我遵循了一些指南和其他問題,我認爲,但我有一個錯誤,我無法修復。Asynctask和doInBackground的錯誤

針對此線

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

我收到此錯誤

The type MainActivity.loadNotams must implement the inherited abstract method AsyncTask.doInBackground(String...)

,並針對此線

protected Void doInBackground(String airfield) { 

我收到此錯誤:

The method doInBackground(String) of type MainActivity.loadNotams must override or implement a supertype method

這裏的任何想法是我的全部代碼:

import java.io.IOException; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

TextView testText; 
Notam[] notamList = new Notam[100]; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    // Document doc = null; 

    testText = (TextView) findViewById(R.id.textview); 

    new loadNotams().execute("ybmk"); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

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

    @Override 
    protected Void doInBackground(String airfield) { 
     Document doc = null; 

     try { 
      doc = Jsoup 
        .connect(
          "https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs") 
        .data("retrieveLocId", airfield) 
        .data("formatType", "ICAO") 
        .data("reportType", "REPORT") 
        .data("actionType", "notamRetrievalByICAOs") 
        // .userAgent("Mozilla") 
        // .cookie("auth", "token") 
        .timeout(3000).post(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     int counter = 0; 
     Elements pre = doc.select("pre"); 

     for (Element link : pre) { 

      // get the value from href attribute 
      System.out.println("text : " + link.text()); 
      notamList[counter++] = new Notam(airfield, link.text() 
        .substring(0, 8), link.text().substring(11, 
        link.text().length())); 

     } 
     counter--; 
     while (counter >= 0) { 
      System.out.println("class : " + notamList[counter].identifier 
        + "#" + notamList[counter].notamText); 
      counter--; 
     } 
     testText.setText(notamList[0].notamText); 
     return null; 
    } 
} 

}

回答

2

變化

protected Void doInBackground(String airfield) 

protected Void doInBackground(String... airfield) 

protected Void doInBackground(String[] airfield) 

如doInBackground()方法需要字符串數組作爲參數

,改變到

try { 
     doc = Jsoup 
       .connect(
         "https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs") 
       .data("retrieveLocId", airfield[0]) 
       .data("formatType", "ICAO") 
       .data("reportType", "REPORT") 
       .data("actionType", "notamRetrievalByICAOs") 
       // .userAgent("Mozilla") 
       // .cookie("auth", "token") 
       .timeout(3000).post(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
+1

由於戈帕爾。像魅力一樣工作。堆棧溢出岩石! – Gavin

0

使它成爲一個可變參數的方法

protected Void doInBackground(String... airfield) 
相關問題