我是 android 新手,我正在尝试使用 jsoup 从网站返回数据,但是当我执行 get() 方法时出现异常。这是我的代码:
public void Iqama (View view) throws IOException
{
Document doc = Jsoup.connect("http://google.com/").get();
}
这是我的日志猫
06-07 12:59:38.428: E/AndroidRuntime(2281): FATAL EXCEPTION: main
06-07 12:59:38.428: E/AndroidRuntime(2281): java.lang.IllegalStateException: Could not execute method of the activity
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.view.View$1.onClick(View.java:3735)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.view.View.performClick(View.java:4354)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.view.View$PerformClick.run(View.java:17948)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.os.Handler.handleCallback(Handler.java:725)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.os.Handler.dispatchMessage(Handler.java:92)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.os.Looper.loop(Looper.java:137)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.app.ActivityThread.main(ActivityThread.java:5293)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.lang.reflect.Method.invoke(Method.java:511)
06-07 12:59:38.428: E/AndroidRuntime(2281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-07 12:59:38.428: E/AndroidRuntime(2281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-07 12:59:38.428: E/AndroidRuntime(2281): at dalvik.system.NativeStart.main(Native Method)
06-07 12:59:38.428: E/AndroidRuntime(2281): Caused by: java.lang.reflect.InvocationTargetException
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.lang.reflect.Method.invoke(Method.java:511)
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.view.View$1.onClick(View.java:3730)
06-07 12:59:38.428: E/AndroidRuntime(2281): ... 11 more
06-07 12:59:38.428: E/AndroidRuntime(2281): Caused by: android.os.NetworkOnMainThreadException
06-07 12:59:38.428: E/AndroidRuntime(2281): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
06-07 12:59:38.428: E/AndroidRuntime(2281): at java.net.InetAddress.getAllByName(InetAddress.java:214)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
06-07 12:59:38.428: E/AndroidRuntime(2281): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
06-07 12:59:38.428: E/AndroidRuntime(2281): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
06-07 12:59:38.428: E/AndroidRuntime(2281): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
06-07 12:59:38.428: E/AndroidRuntime(2281): at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
06-07 12:59:38.428: E/AndroidRuntime(2281): at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
06-07 12:59:38.428: E/AndroidRuntime(2281): at rasha.example.masjed.Second.Iqama(Second.java:35)
06-07 12:59:38.428: E/AndroidRuntime(2281): ... 14 more
06-07 12:59:51.831: I/Process(2281): Sending signal. PID: 2281 SIG: 9
06-07 12:59:52.151: D/libEGL(3235): loaded /system/lib/egl/libEGL_adreno200.so
06-07 12:59:52.151: D/libEGL(3235): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
06-07 12:59:52.151: D/libEGL(3235): loaded /system/lib/egl/libGLESv2_adreno200.so
06-07 12:59:52.161: I/Adreno200-EGL(3235): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: (CL3544079)
06-07 12:59:52.161: I/Adreno200-EGL(3235): Build Date: 03/28/13 Thu
06-07 12:59:52.161: I/Adreno200-EGL(3235): Local Branch: adreno_20130328
06-07 12:59:52.161: I/Adreno200-EGL(3235): Remote Branch:
06-07 12:59:52.161: I/Adreno200-EGL(3235): Local Patches:
06-07 12:59:52.161: I/Adreno200-EGL(3235): Reconstruct Branch:
06-07 12:59:52.201: D/OpenGLRenderer(3235): Enabling debug mode 0
06-07 13:00:22.140: W/IInputConnectionWrapper(3235): setComposingText on inactive InputConnection
这是我的 Mainfest 文件
android:minSdkVersion="8"
android:targetSdkVersion="16" />
并在清单中的应用程序标记之前使用此权限
<uses-permission android:name="android.permission.INTERNET"/>
我在 libs 文件夹中使用 JSOUP-1.7.2.jar