コードはJavaコンソールでは正常に機能しますが、Androidエミュレーターではエラーが発生します。同じタイプの他の投稿をチェックしましたが、成功しませんでした...
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();
}
}
}
以下はエラーです......
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)