我厌倦了oracle的示例,从带有android的URLConnection中读取这是代码
``try{
URL oracle = new URL("http://www.oracle.com/");
Proxy proxy = new Proxy(Proxy.Type.HTTP,newInetSocketAddress("192.168.3.254",3128)); // or whatever your proxy is
URLConnection yc = oracle.openConnection(proxy);
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
Toast.makeText(this, inputLine, Toast.LENGTH_SHORT);
in.close();
}
catch(IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
我注意到我的代理模拟器设置已配置我有这个日志错误
>04-20 14:20:21.842: D/AndroidRuntime(988): 关闭 VM 04-20 14:20:21.842: W/dalvikvm(988): threadid=1: 线程退出但未捕获异常 (group=0x409c01f8) 04-20 14:20:21.862: E/AndroidRuntime(988): 致命异常: main 04-20 14:20:21.862: E/AndroidRuntime(988): java.lang.RuntimeException: 无法启动活动 ComponentInfo{connect. oracle.java/connect.oracle.java.ConnectActivity}: android.os.NetworkOnMainThreadException 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 04 -20 14:20:21.862: E/AndroidRuntime(988): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app .ActivityThread.access$600(ActivityThread.java:123) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app。ActivityThread$H.handleMessage(ActivityThread.java:1147) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.os.Handler.dispatchMessage(Handler.java:99) 04-20 14:20: 21.862: E/AndroidRuntime(988): 在 android.os.Looper.loop(Looper.java:137) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app.ActivityThread.main(ActivityThread .java:4424) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 java.lang.reflect.Method.invokeNative(Native Method) 04-20 14:20:21.862: E/AndroidRuntime(988) : 在 java.lang.reflect.Method.invoke(Method.java:511) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit .java:784) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-20 14:20:21.862: E /AndroidRuntime(988):在 dalvik.system.NativeStart。main(本机方法)04-20 14:20:21.862:E/AndroidRuntime(988):由:android.os.NetworkOnMainThreadException 04-20 14:20:21.862:E/AndroidRuntime(988):在 android.os。 StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 04-20 14:20:21.862: E/AndroidRuntime(988): at java.net.InetAddress.getHostByAddrImpl(InetAddress.java:440) 04-20 14:20: 21.862: E/AndroidRuntime(988): 在 java.net.InetAddress.getHostName(InetAddress.java:313) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 java.net.InetSocketAddress.getHostName(InetSocketAddress .java:156) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 libcore.net.http.HttpConnection$Address.(HttpConnection.java:322) 04-20 14:20:21.862: E/ AndroidRuntime(988): 在 libcore.net.http.HttpConnection.connect(HttpConnection.java:96) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 libcore.net.http。HttpEngine.openSocketConnection(HttpEngine.java:308) 04-20 14:20:21.862: E/AndroidRuntime(988): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 04-20 14:20: 21.862: E/AndroidRuntime(988): 在 libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 libcore.net.http.HttpEngine .sendRequest(HttpEngine.java:232) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273) 04-20 14:20:21.862 : E/AndroidRuntime(988): 在 libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 connect.oracle.java.ConnectActivity。 onCreate(ConnectActivity.java:22) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app.Activity.performCreate(Activity.java:4465) 04-20 14:20:21.862: E/AndroidRuntime(988): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 04-20 14:20:21.862: E/AndroidRuntime(988): 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 04-20 14:20:21.862: E/AndroidRuntime(988): ... 11 更多
并提前谢谢你