Asynctask 和 doInBackground 错误 [英] Asynctask and doInBackground errors

查看:45
本文介绍了Asynctask 和 doInBackground 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了一些指南和其他我认为完全正确的问题,但我有一个无法修复的错误.

I have followed a number of guides and other questions I think exactly but I have an error that I can't fix.

反对这条线

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

我收到此错误

MainActivity.loadNotams 类型必须实现继承的抽象方法 AsyncTask.doInBackground(String...)

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

反对这条线

protected Void doInBackground(String airfield) {

我收到此错误:

MainActivity.loadNotams 类型的 doInBackground(String) 方法必须覆盖或实现超类型方法

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

这里的任何想法都是我的完整代码:

Any ideas here is my whole code:

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;
    }
}

}

推荐答案

change

 protected Void doInBackground(String airfield)

 protected Void doInBackground(String... airfield)

 protected Void doInBackground(String[] airfield)

因为 doInBackground() 方法需要字符串数组作为参数

as doInBackground() methods requires array of Strings as parameter

并更改为

   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();
    }

这篇关于Asynctask 和 doInBackground 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆