1

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

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)
4

1 回答 1

0

我很确定存在 jar 问题。

做以下。

在应用程序层次结构的“根”中创建一个名为“libs”的文件夹(与 src、gen 等一起),并将 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();

    }
}
于 2012-06-12T12:29:00.727 回答