Android的AsyncTask .add代码说cabbıt解析



我找不到任何异步任务的代码或资源,所以我把它放在这里。对不起,但我怎么能纠正这个代码?

    package com.example.tarko.deneme;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import org.jsoup.Jsoup;
    import org.jsoup.select.Elements;
    import org.w3c.dom.Document;
    import java.io.IOException;
    import java.util.Calendar;
    /**
    * Created by tarko on 25.08.2016.
    */
    public abstract class AsyncTask2 extends AsyncTask<Void, Void, Void>               {

    @Override
    protected void onPreExecute(){
    super.onPreExecute();
    }
    @Override
    protected Void doInBackground(String... params){
    try{

      Bundle lastPosts = null;
      lastPosts.clear();
      org.jsoup.nodes.Document doc = Jsoup.connect(params[0]).get();
      //Ana Elementler
      Elements div_content_left = doc. select("div[id=conent-left]");
      Elements div_home_article = div_content_left.select("div[class=home-article");
      //Ara Başlıklar
      Elements div_article_title = div_home_article.select("div[class=article-title]");
      Elements div_article_content = div_home_article.select("div[class=article-content");
      Elements div_article_short = div_home_article.select("div[class=article-short]");
      //Son Elementler
      Elements images = div_article_content.select("img");
      Elements p = div_article_short.select("p");
      Elements h1 = div_article_title.select("h1");
      Elements a = h1.select("a");
      for (int i=0; i<a.size(); i++){
      lastPosts.add(new Post(a.get(i).text(),a.get(i).attr("href"),p.get(i).text()));
          resimAdresleri.add(images.get(i).attr("src"));
  }

    return null;
} catch (IOException e) {
      e.printStackTrace();
  }
    @Override
protected void onPostExecute(Void result){
    super.onPostExecute(result);
}
@Override
protected void onProgressUpdate(Void... values){
    super.onProgressUpdate(values);
}
@Override
protected void onCancelled(Void result){
    super.onCancelled(result);
}
}}

在。add samples上出错,它说不能解析方法。代码改变了吗?

因为Bundle没有称为add()的方法而出错。相反,它有Bundle.putString(), Bundle.putInt()等。

查看文档,看看最适合你的方法。

同样,即使你让它编译,它也会在运行时失败,因为这行代码:

Bundle lastPosts = null;
lastPosts.clear();

这将导致NullPointerException,确保您初始化Bundle:

Bundle lastPosts = new Bundle();

相关内容

  • 没有找到相关文章

最新更新