The code works fine in java console but when in android emulator it gives an error. I have checked other post of the same type but got 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();
}
}
}
following is the 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)
You’re getting a
NoClassDefFoundErrorbecause your jar file is not available at runtime. In order for it to be available at runtime you’ll have to put it in your libs folder and check the checkboxes on your jar file in your java build path like so: