Jsoup和Android错误

时间:2014-08-24 22:00:03

标签: android jsoup

有人可以告诉我为什么我在启动主要活动时会出现此错误? 我不明白为什么。 “应用程序进程意外停止了”我在模拟器上有这个 提前谢谢,对不起我的英语,我是法国人。

这是我的代码:

package alpha.omega.alphastreaming;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;


public class MainActivity extends Activity {

    // URL Address
    String url ="http://seriestreaming.org/";
    ProgressDialog mProgressDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Description().execute();


}
    // Description AsyncTask
        private class Description extends AsyncTask<Void, Void, Void> {
            String b;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                mProgressDialog = new ProgressDialog(MainActivity.this);
                mProgressDialog.setTitle("Android ");
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                mProgressDialog.show();
            }

            @Override
            protected Void doInBackground(Void... params) {
                int i=0;
                ArrayList<String> a= new Consumer().Start(i);
                 b=a.get(2);
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                // Set description into TextView
                TextView txttitle = (TextView) findViewById(R.id.textView3);
                txttitle.setText(b);
                mProgressDialog.dismiss();
            }
        }
    public ArrayList<String>  Start(int i) 
    {
        i = 10;

        return crawl(i);
    }
    private ArrayList<String> crawl(int i) 
    {
        String crawlUrl = this.getCrawlUrl();
        ArrayList<String> titleSerie = new ArrayList<String>();
        try {
            Document doc = Jsoup.connect(crawlUrl).timeout(25000).get();
            Elements hrefs = doc.select("div.movief").select("a[href]");

            for (Element e : hrefs) {
                titleSerie.add(e.text());

            }
            System.out.println(titleSerie.get(i));

        } catch (IOException ex) {
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        }
        return titleSerie;
    }
    private String getCrawlUrl() {
        String url = "http://seriestreaming.org/";
        return url;
    }

}

这是logCat:

08-24 21:44:30.906: E/AndroidRuntime(301): FATAL EXCEPTION: AsyncTask #1
08-24 21:44:30.906: E/AndroidRuntime(301): java.lang.RuntimeException: An error occured while executing doInBackground()
08-24 21:44:30.906: E/AndroidRuntime(301):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.lang.Thread.run(Thread.java:1096)
08-24 21:44:30.906: E/AndroidRuntime(301): Caused by: java.lang.NoSuchMethodError: java.lang.String.isEmpty
08-24 21:44:30.906: E/AndroidRuntime(301):  at org.jsoup.helper.DataUtil.getCharsetFromContentType(DataUtil.java:173)
08-24 21:44:30.906: E/AndroidRuntime(301):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:484)
08-24 21:44:30.906: E/AndroidRuntime(301):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
08-24 21:44:30.906: E/AndroidRuntime(301):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
08-24 21:44:30.906: E/AndroidRuntime(301):  at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
08-24 21:44:30.906: E/AndroidRuntime(301):  at alpha.omega.alphastreaming.Consumer.crawl(Consumer.java:25)
08-24 21:44:30.906: E/AndroidRuntime(301):  at alpha.omega.alphastreaming.Consumer.Start(Consumer.java:18)
08-24 21:44:30.906: E/AndroidRuntime(301):  at alpha.omega.alphastreaming.MainActivity$Description.doInBackground(MainActivity.java:50)
08-24 21:44:30.906: E/AndroidRuntime(301):  at alpha.omega.alphastreaming.MainActivity$Description.doInBackground(MainActivity.java:1)
08-24 21:44:30.906: E/AndroidRuntime(301):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-24 21:44:30.906: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-24 21:44:30.906: E/AndroidRuntime(301):  ... 4 more
08-24 21:44:32.145: E/WindowManager(301): Activity alpha.omega.alphastreaming.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e643f0 that was originally added here
08-24 21:44:32.145: E/WindowManager(301): android.view.WindowLeaked: Activity alpha.omega.alphastreaming.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e643f0 that was originally added here
08-24 21:44:32.145: E/WindowManager(301):   at android.view.ViewRoot.<init>(ViewRoot.java:247)
08-24 21:44:32.145: E/WindowManager(301):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-24 21:44:32.145: E/WindowManager(301):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-24 21:44:32.145: E/WindowManager(301):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.Dialog.show(Dialog.java:241)
08-24 21:44:32.145: E/WindowManager(301):   at alpha.omega.alphastreaming.MainActivity$Description.onPreExecute(MainActivity.java:44)
08-24 21:44:32.145: E/WindowManager(301):   at android.os.AsyncTask.execute(AsyncTask.java:391)
08-24 21:44:32.145: E/WindowManager(301):   at alpha.omega.alphastreaming.MainActivity.onCreate(MainActivity.java:29)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-24 21:44:32.145: E/WindowManager(301):   at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 21:44:32.145: E/WindowManager(301):   at android.os.Looper.loop(Looper.java:123)
08-24 21:44:32.145: E/WindowManager(301):   at android.app.ActivityThread.main(ActivityThread.java:4627)
08-24 21:44:32.145: E/WindowManager(301):   at java.lang.reflect.Method.invokeNative(Native Method)
08-24 21:44:32.145: E/WindowManager(301):   at java.lang.reflect.Method.invoke(Method.java:521)
08-24 21:44:32.145: E/WindowManager(301):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-24 21:44:32.145: E/WindowManager(301):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-24 21:44:32.145: E/WindowManager(301):   at dalvik.system.NativeStart.main(Native Method)

对不起,我忘记了消费者类:

import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Consumer {

    public ArrayList<String>  Start(int i) {
        i = 10;

        return crawl(i);
    }

    private ArrayList<String> crawl(int i) {
        String crawlUrl = this.getCrawlUrl();
        ArrayList<String> titleSerie = new ArrayList<String>();
        try {
            Document doc = Jsoup.connect(crawlUrl).timeout(25000).get();
            Elements hrefs = doc.select("div.movief").select("a[href]");

            for (Element e : hrefs) {
                titleSerie.add(e.text());

            }
            System.out.println(titleSerie.get(i));

        } catch (IOException ex) {
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        }
        return titleSerie;
    }

    private String getCrawlUrl() {
        String url = "http://seriestreaming.org/";
        return url;
    }
}

enter code here

0 个答案:

没有答案