2012-06-12 136 views
1

喜的朋友即時通訊使用本教程http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/後,我實現了這個代碼我的應用程序已經停止我不知道爲什麼PLZ建議我在此先感謝使用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) 

回答

0

我敢肯定有jar問題。

請執行以下操作。

在名爲「libs」的app heirarchy(旁邊是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(); 

    } 
} 
+0

感謝VIPUL但仍然得到問題它顯示在文本視圖中錯誤指的例外是有PLZ盡力解決 – Mohit

+0

JsopuexampleActivity.java:24 <---你在這個line.paste有錯誤你的源代碼在這裏。 –

+0

源代碼是在下面的教程http://xjaphx.wordpress.com/2012/02/04/android-xml-adventure-parsing-html-using-jsoup/ – Mohit