java.net.SocketTimeoutException: connect timed out

报错记录:

java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
at java.net.Socket.connect(Socket.java:586)

原因及解决:

设置timeout时间

HttpUrlConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(8000); 

你可能感兴趣的:(魅力安卓,android,android,studio,Android分享,报错信息,报错记录)