我对Android编程很陌生,但是我习惯于为iOS编程...
现在在 iOS 中你有了 NSString stringWithContentOfURL 的功能。现在我的问题是,如果java中也有类似的选项......?在谷歌搜索时,我遇到了一些例子,但使用它们我的应用程序总是崩溃......
我使用了这样的代码:http: //www.coderzheaven.com/2011/07/17/how-to-read-webpage-contents-as-a-string-in-android/但它一直在崩溃......可以你帮帮我好吗?
谢谢!
编辑:LogCat 错误:
01-22 19:34:12.718: E/AndroidRuntime(5481): FATAL EXCEPTION: main
01-22 19:34:12.718: E/AndroidRuntime(5481): android.os.NetworkOnMainThreadException
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
01-22 19:34:12.718: E/AndroidRuntime(5481): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.example.test4.DieActivity.meldeAn(DieActivity.java:150)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.example.test4.DieActivity$1.onClick(DieActivity.java:56)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.view.View.performClick(View.java:3511)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.view.View$PerformClick.run(View.java:14105)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Handler.handleCallback(Handler.java:605)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.os.Looper.loop(Looper.java:137)
01-22 19:34:12.718: E/AndroidRuntime(5481): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 19:34:12.718: E/AndroidRuntime(5481): at java.lang.reflect.Method.invoke(Method.java:511)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-22 19:34:12.718: E/AndroidRuntime(5481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-22 19:34:12.718: E/AndroidRuntime(5481): at dalvik.system.NativeStart.main(Native Method)