当前位置: 代码迷 >> Android >> java.net.SocketException: The operation timed out,该怎么处理
  详细解决方案

java.net.SocketException: The operation timed out,该怎么处理

热度:53   发布时间:2016-05-01 22:03:28.0
java.net.SocketException: The operation timed out
W/System.err( 8456): java.net.SocketException: The operation timed out
W/System.err( 8456): at org.apache.harmony.luni.platform.OSNetworkSystem.conn
ectStreamWithTimeoutSocketImpl(Native Method)
W/System.err( 8456): at org.apache.harmony.luni.platform.OSNetworkSystem.conn
ect(OSNetworkSystem.java:115)
W/System.err( 8456): at org.apache.harmony.luni.net.PlainSocketImpl.connect(P
lainSocketImpl.java:244)
W/System.err( 8456): at org.apache.harmony.luni.net.PlainSocketImpl.connect(P
lainSocketImpl.java:533)
W/System.err( 8456): at java.net.Socket.connect(Socket.java:1055)
W/System.err( 8456): at org.apache.http.conn.scheme.PlainSocketFactory.connec
tSocket(PlainSocketFactory.java:119)
W/System.err( 8456): at org.apache.http.impl.conn.DefaultClientConnectionOper
ator.openConnection(DefaultClientConnectionOperator.java:143)
W/System.err( 8456): at org.apache.http.impl.conn.AbstractPoolEntry.open(Abst
ractPoolEntry.java:164)
W/System.err( 8456): at org.apache.http.impl.conn.AbstractPooledConnAdapter.o
pen(AbstractPooledConnAdapter.java:119)
W/System.err( 8456): at org.apache.http.impl.client.DefaultRequestDirector.ex
ecute(DefaultRequestDirector.java:348)
W/System.err( 8456): at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:555)
W/System.err( 8456): at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:653)
W/System.err( 8456): at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:627)
W/System.err( 8456): at org.apache.http.impl.client.AbstractHttpClient.execut
e(AbstractHttpClient.java:616)
W/System.err( 8456): at com.example.android.apis.ApiDemos$2.run(ApiDemos.java
:260)
D/dalvikvm( 2157): GC_EXPLICIT freed 1082 objects / 54648 bytes in 144ms
I/System.out( 8507): [INFO:21472]: c: Response [http=200,length=139]
I/System.out( 8507): [INFO:21476]: c: Read id 1, status code 200
D/dalvikvm( 7979): GC_EXPLICIT freed 42 objects / 1832 bytes in 70ms


private void processThread() {

// 构建一个下载进度条

pd = ProgressDialog.show(ApiDemos.this, "Load", "Loading…");

new Thread() {

public void run() {

HttpClient httpclient = new DefaultHttpClient(); 
HttpGet request = new HttpGet(
"http://webservice.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx/getForexRmbRate"); 
// //
// httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
// 5000);
// httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
// 5000);
String response;

try {
response = httpclient.execute(request,
new BasicResponseHandler());
StringReader read = new StringReader(response);
InputSource in = new InputSource(read);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp;
sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
RateHandler rh = new RateHandler();
xr.setContentHandler(rh);
xr.parse(in);
List<Rate> rates = rh.getRates();

Message msg = handler.obtainMessage(1, rates);
pd.dismiss();

handler.sendMessage(msg);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
  相关解决方案