Błędy Asynctask i doInBackground
Podążyłem za wieloma przewodnikami i innymi pytaniami, które uważam za dokładnie, ale mam błąd, którego nie mogę naprawić.
Na tej linii
private class loadNotams extends AsyncTask<String, Void, Void> {
Dostaję ten błąd
Typ MainActivity.loadNotams musi implementować odziedziczoną metodę abstrakcyjną AsyncTask.doInBackground (String ...)
i przeciwko tej linii
protected Void doInBackground(String airfield) {
Dostaję ten błąd:
Metoda doInBackground (String) typu MainActivity.loadNotams musi zastąpić lub zaimplementować metodę nadtypu
Wszelkie pomysły tutaj to mój cały kod:
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;
}
}
}