Jsoup error while parsing html

The code works fine in java console but when the error appears in android emulator. I checked another post of the same type, but no success ...

import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;

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

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Geocoder;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class AndroidGPSTrackingActivity extends Activity {
//some code which calls directions

    }



    public void directions() {
        try {

                        Document doc = Jsoup.connect("http://10.0.2.2/kj/jhjh.htm")
                    .get();////////////////error occurs here
            Elements el = doc.getElementsByClass("lkklk");
            String str = el.text();
            str = str.replaceAll("[0-9]+[.] ", "\n");
            string = str.split("\n");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

      

next error ...

01-19 05:34:35.723: E/AndroidRuntime(952): FATAL EXCEPTION: main
01-19 
05:34:35.723: E/AndroidRuntime(952): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
01-19 
05:34:35.723: E/AndroidRuntime(952):    at com.example.gpstracking.AndroidGPSTrackingActivity.directions(AndroidGPSTrackingActivity.java:308)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at com.example.gpstracking.AndroidGPSTrackingActivity.onActivityResult(AndroidGPSTrackingActivity.java:193)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.app.Activity.dispatchActivityResult(Activity.java:5192)

01-19 05:34:35.723: E/AndroidRuntime(952):  at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.app.ActivityThread.access$1100(ActivityThread.java:130)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at android.os.Looper.loop(Looper.java:137)

01-19 05:34:35.723: E/AndroidRuntime(952):  at android.app.ActivityThread.main(ActivityThread.java:4745)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at java.lang.reflect.Method.invokeNative(Native Method)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at java.lang.reflect.Method.invoke(Method.java:511)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-19 
05:34:35.723: E/AndroidRuntime(952):    at dalvik.system.NativeStart.main(Native Method)

      

+3


source to share


1 answer


You get NoClassDefFoundError

because your jar file is not available at runtime. To make it available at runtime, you will have to put it in your folder with folders and check the boxes in your jar file in the java build path like this:



enter image description here

+1


source







All Articles