Android:org.apache.http.conn.ConnectTimeoutException

时间:2014-01-07 11:04:40

标签: android android-emulator

当我的应用程序启动时,它会在logcat上显示org.apache.http.conn.ConnectTimeoutException。我该如何解决这个问题?

GC_CONCURRENT freed 9249K, 41% free 18445K/31159K, paused 2ms+3ms
01-07 16:22:53.160: I/System.out(18960): [socket][2:54002] exception
01-07 16:22:53.160: I/System.out(18960): [CDS]close[54002]
01-07 16:22:53.160: I/System.out(18960): close [socket][/0.0.0.0:54002]
01-07 16:22:53.160: W/System.err(18960): org.apache.http.conn.ConnectTimeoutException: Connect to /193.42.223.82:443 timed out
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:363)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-07 16:22:53.161: W/System.err(18960):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-07 16:22:53.161: W/System.err(18960):    at com.axis.cbk.httpmodel.CustomHttpClient.executeHttpGet(CustomHttpClient.java:107)
01-07 16:22:53.161: W/System.err(18960):    at com.axis.cbk.Backg_Proc_for_Lang.onHandleIntent(Backg_Proc_for_Lang.java:41)
01-07 16:22:53.162: W/System.err(18960):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
01-07 16:22:53.165: W/System.err(18960):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 16:22:53.166: W/System.err(18960):    at android.os.Looper.loop(Looper.java:154)
01-07 16:22:53.166: W/System.err(18960):    at android.os.HandlerThread.run(HandlerThread.java:65)
01-07 16:22:53.170: D/ActivityThread(18960): SVC-Destroying service: com.axis.cbk.Backg_Proc_for_Lang@41ffd7a0
01-07 16:22:53.171: D/dalvikvm(18960): threadid=11: exiting
01-07 16:22:53.171: D/dalvikvm(18960): threadid=11: bye!
01-07 16:22:53.171: D/dalvikvm(18960): threadid=0: freeing

1 个答案:

答案 0 :(得分:0)

试试这个.......

 private static long TIME_OUT_IN_SECONDS = 120;

 httpResponse = httpClient.execute(httpPost);
 long requestEndTime = new Date().getTime();
 long timeOfRequest = (requestEndTime - requestStratTime) / 1000;
 if (httpResponse == null && timeOfRequest > TIME_OUT_IN_SECONDS) {
      throw new TimeOutException();
 }

当数据花费太多时间来响应请求时,就会发生这种情况,您将丢失抛出超时异常。