在我的應用程序編寫代碼,用於連接到網址,如下所示java.net.socketexception:Android中的操作超時問題?
InputStream inputStream = new URL(url).openStream();
我得到了error.Iam送我的logcat
12-17 15:06:55.065: WARN/System.err(4952): java.net.SocketException: The operation timed out
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
12-17 15:06:55.075: WARN/System.err(4952): at java.net.Socket.connect(Socket.java:1055)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
12-17 15:06:55.085: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
12-17 15:06:55.085: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1152)
12-17 15:06:55.085: WARN/System.err(4952): at java.net.URL.openStream(URL.java:653)
如何解決這個問題
什麼是網址?你確定你的服務器已經啓動了嗎? – 2010-12-17 12:36:02
是可以訪問的服務器,它接受連接嗎? – mad 2010-12-17 12:36:30
是的,我的服務器已啓動,並且此錯誤僅在某些時間發生 – ADIT 2010-12-17 12:57:26