AsyncTask#1执行doInBackground()时发生错误

时间:2014-10-30 20:18:08

标签: java android android-asynctask jsoup

这是我的代码和日志消息

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.raspored);

    Bundle bundle = getIntent().getExtras();
    url = bundle.getString("url");
    new FetchWebsiteData().execute();
}


private class FetchWebsiteData extends AsyncTask<Void, Void, Void> {
    String eles = "";

    /*@Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(Raspored.this);
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }*/

    @Override
    protected Void doInBackground(Void... params) {
        try {
             // Connect to website
            Document document = Jsoup.connect(url).get();
            // Get the html document title
            //websiteTitle = document.title();
            Element elementsByTag = document.body();
            Element tablica = elementsByTag.getElementsByTag("table").get(9).getElementsByTag("td").get(4);
            Elements redak = tablica.getElementsByTag("ul");
            eles = redak.text().toString();

        } catch (IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // Set title into TextView
        TextView txttitle = (TextView) findViewById(R.id.tbl_txt);
        txttitle.setMovementMethod(new ScrollingMovementMethod());
        //txttitle.setText(websiteTitle + "\n" + eles);
        String ele = eles.replace(" ", "\n");
        arr_linkText.add(ele);
        for(String temp : arr_linkText) {
            txttitle.append(temp);
        }     
        //mProgressDialog.dismiss();  
    }

  }
}

日志:

10-30 21:04:54.554: E/AndroidRuntime(27047): FATAL EXCEPTION: AsyncTask #1
10-30 21:04:54.554: E/AndroidRuntime(27047): java.lang.RuntimeException: An error occured while executing doInBackground() 
10-30 21:04:54.554:E/AndroidRuntime(27047):atandroid.os.AsyncTask$3.done (AsyncTask.java:299)    
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.lang.Thread.run(Thread.java:856)
10-30 21:04:54.554: E/AndroidRuntime(27047): Caused by: java.lang.NoClassDefFoundError: org.jsoup.Jsoup
10-30 21:04:54.554: E/AndroidRuntime(27047):    at com.project.busme.Raspored$FetchWebsiteData.doInBackground(Raspored.java:52)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at com.project.busme.Raspored$FetchWebsiteData.doInBackground(Raspored.java:1)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-30 21:04:54.554: E/AndroidRuntime(27047):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-30 21:04:54.554: E/AndroidRuntime(27047):    ... 5 more

这里有什么问题?

1 个答案:

答案 0 :(得分:0)

你确定jsoup jar在类路径中吗? 确保你的apk中添加了jsoup jar。