java.net.ConnectException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14826497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:31:01  来源:igfitidea点击:

java.net.ConnectException

javaandroidhttpwebrequesttetheringgoogle-nexus

提问by Sam

When I'm running my app through Google Nexus by connecting through USB and trying to connect webservice running on my laptop then I'm getting below error but I'm able to connect to webservie. Please advice.

当我通过 USB 连接并尝试连接在我的笔记本电脑上运行的网络服务通过 Google Nexus 运行我的应用程序时,我遇到以下错误,但我能够连接到网络服务。请指教。

     java.net.ConnectException: failed to connect to /192.168.1.122 (port 8080):       
           connect failed: ENETUNREACH (Network is unreachable)

            at libcore.io.IoBridge.connect(IoBridge.java:114)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:566)
            at java.net.Socket.tryAllAddresses(Socket.java:127)
            at java.net.Socket.<init>(Socket.java:177)
            at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
            at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
            at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
            at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
            at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
            at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
            at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

回答by Thihara

Just because you connect the phone to the computer don't mean that it will create a network connection.

仅仅因为您将手机连接到计算机并不意味着它会创建网络连接。

Create a LAN run the web-service on the LAN IP. and use wifi to connect to it.

创建一个 LAN,在 LAN IP 上运行 Web 服务。并使用wifi连接到它。

回答by Quintin Balsdon

You need to publish the services to a location where your phone can connect to them via the Wireless Lan. The USB is only for debugging purposes

您需要将服务发布到您的手机可以通过无线局域网连接到它们的位置。USB 仅用于调试目的