使用Jsoup我的应用程序已被强制停止

时间:2012-06-12 12:23:55

标签: android jsoup

朋友们,我正在使用本教程http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/,在我实现此代码后,我的应用程序已经停止了,我不知道为什么plz建议我提前感谢

06-12 17:35:29.912: E/AndroidRuntime(1250): FATAL EXCEPTION: main
06-12 17:35:29.912: E/AndroidRuntime(1250): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
06-12 17:35:29.912: E/AndroidRuntime(1250): at your.packag.namespace.JsopuexampleActivity.getBlogStats(JsopuexampleActivity.java:33)
06-12 17:35:29.912: E/AndroidRuntime(1250): at your.packag.namespace.JsopuexampleActivity.onCreate(JsopuexampleActivity.java:24)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.Activity.performCreate(Activity.java:4465)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.os.Looper.loop(Looper.java:137)
06-12 17:35:29.912: E/AndroidRuntime(1250): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-12 17:35:29.912: E/AndroidRuntime(1250): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 17:35:29.912: E/AndroidRuntime(1250): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 17:35:29.912: E/AndroidRuntime(1250): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-12 17:35:29.912: E/AndroidRuntime(1250): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-12 17:35:29.912: E/AndroidRuntime(1250): at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

我很确定存在jar问题。

请遵循。

在应用程序heirarchy(与src,gen等一起)的“root”中创建一个名为“libs”的文件夹,然后将jar文件放在那里。清理/构建并重新启动应用程序时,错误应该消失。

下面是正确的代码。

package org.sample;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Hello extends Activity {

    final String BLOG_URL = "http://xjaphx.wordpress.com/";
    private String result;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // set layout view
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getBlogStats();

    }

    protected void getBlogStats() {
    ((TextView) findViewById(R.id.text)).setText("Please Wait!");
        new Thread() {
            public void run() {

                Document document;
                try {
                    document = Jsoup.connect(BLOG_URL).get();
                    Elements nodeBlogStats = document
                            .select("div#blog-stats ul li");

                    if (nodeBlogStats.size() > 0) {
                        result = nodeBlogStats.get(0).text();
                    }
                } catch (IOException e) {
                    result = "Error";
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {

                    public void run() {
                        ((TextView) findViewById(R.id.text)).setText(result);
                    }
                });

            }
        }.start();

    }
}