2012-10-15 1 views
-1

인터넷 연결없이 일부 데이터를 보내려고 할 때 HttpHostConnectException을 처리하려고합니다.강제 종료 팝업 사용 안드로이드

catch (HttpHostConnectException e) { 

       client.getConnectionManager().shutdown(); 
       try { 
        throw new NoInternetException(); 
       } catch (NoInternetException e1) { 
        inetError = true; 
        e1.printStackTrace(); 
       } 

       e.printStackTrace(); 
      } 

내 활동에 나는 예외를 잡을 때 :

catch(NoInternetException e) { 
      this.cancel(true); 
      editor.clear(); 
      editor.commit(); 
      finish(); 
      startActivity(getIntent()); 
      Toast.makeText(LoginActivity.this, "You've lost internet connection. You should try later.",Toast.LENGTH_LONG) 
       .show(); 
      e.printStackTrace(); 
      } 

을 나는 현재 활동을 다시 시작,이 예외를 처리하는 I가 서버에 연결하는 곳 내 위해 RESTClient 클래스에서이 같은 그것을 할 사용자가 마지막으로 사용한 시간이며 "연결되지 않았습니다."와 같은 토스트를 표시합니다. 하지만 강제 종료 버튼으로 예외 팝업이 표시됩니다. 내가 보여주고 싶지는 않지만 활동을 다시로드하고 내 메시지로 토스트를 보여주고 싶습니다. 어떻게 구현할 수 있습니까? 예외

스택 트레이스 : 당신은 아마 당신의 UI 스레드에서이 HttpConnection에 실행하고 있기 때문에

com.library.NoInternetException 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:447) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
org.apache.http.conn.HttpHostConnectException: Connection to https://192.168.0.250 refused 
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178) 
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:401) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
Caused by: java.net.ConnectException: /192.168.0.250:443 - Network is unreachable 
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207) 
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437) 
    at java.net.Socket.connect(Socket.java:1002) 
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143) 
... 14 more 
Error converting result java.lang.NullPointerException 
End of input at character 0 of 
java.lang.InterruptedException 
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1272) 
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:220) 
    at java.util.concurrent.FutureTask.get(FutureTask.java:83) 
    at android.os.AsyncTask$3.done(AsyncTask.java:196) 
    at java.util.concurrent.FutureTask$Sync.innerCancel(FutureTask.java:294) 
    at java.util.concurrent.FutureTask.cancel(FutureTask.java:76) 
    at android.os.AsyncTask.cancel(AsyncTask.java:325) 
    at com.assignmentexpert.LoginActivity$LoginTask.doInBackground(LoginActivity.java:422) 
    at com.assignmentexpert.LoginActivity$LoginTask.doInBackground(LoginActivity.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
cscCountry is not German : SEK 
dashboard 
    10-15 18:48:02.469: I/download page count dashboard(5061): 1 
    10-15 18:48:02.559: D/myLogs(5061): onCreate 
    10-15 18:48:02.559: D/myLogs(5061): onStartCommand 
    10-15 18:48:02.839: I/getOrders start(5061): 1 
    10-15 18:48:03.039: I/getOrders end(5061): 6 
    10-15 18:48:03.039: I/params(5061): page1 
    10-15 18:48:03.039: I/params(5061): perpage6 
    10-15 18:48:03.039: W/dalvikvm(5061): threadid=13: thread exiting with uncaught exception (group=0x40018578) 
    10-15 18:48:03.089: E/AndroidRuntime(5061): FATAL EXCEPTION: AsyncTask #4 
java.lang.RuntimeException: An error occured while executing doInBackground() 

    at android.os.AsyncTask$3.done(AsyncTask.java:200) 
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 
    10-15 18:48:03.089: E/AndroidRuntime(5061):  at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
Caused by: java.lang.NullPointerException 
    at com.library.ServiceMessages.md5(ServiceMessages.java:387) 
    at com.library.ServiceMessages$DklabExecute.doInBackground(ServiceMessages.java:114) 
    at com.library.ServiceMessages$DklabExecute.doInBackground(ServiceMessages.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    ... 4 more 
    10-15 18:48:03.169: I/database closing(5061): All DAO's might be destroyed 
destroy 
com.library.NoInternetException 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:447) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
org.apache.http.conn.HttpHostConnectException: Connection to https://192.168.0.250 refused 
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178) 
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:401) 
    at com.library.RestClient$AsyncExecute.doInBackground(RestClient.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
    at java.lang.Thread.run(Thread.java:1019) 
Caused by: java.net.ConnectException: /192.168.0.250:443 - Network is unreachable 
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207) 
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437) 
    at java.net.Socket.connect(Socket.java:1002) 
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143) 
    ... 14 more 
Error converting result java.lang.NullPointerException 
Error parsing data org.json.JSONException: End of input at character 0 of 
java.lang.NullPointerException 
    at com.library.UserFunctions.getOrders(UserFunctions.java:71) 
    at com.assignmentexpert.DashboardActivityAlt.getOrderList(DashboardActivityAlt.java:318) 
    at com.assignmentexpert.DashboardActivityAlt.access$6(DashboardActivityAlt.java:309) 
    at com.assignmentexpert.DashboardActivityAlt$DownloadTask.doInBackground(DashboardActivityAlt.java:500) 
    at com.assignmentexpert.DashboardActivityAlt$DownloadTask.doInBackground(DashboardActivityAlt.java:1) 
    at android.os.AsyncTask$2.call(AsyncTask.java:185) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
     at java.lang.Thread.run(Thread.java:1019) 
+2

강제 종료는 강제 종료입니다. 응용 프로그램은 기본적으로 커널에서 SIGINT 신호를받습니다. 코드를 가로 채지 말고 코드를 검토하십시오. – shkschneider

+0

강제 종료 오류 로그 캡 트를 표시하십시오. 그러면 도움이 될 것입니다. – YuviDroid

+1

예외가 많습니다 ... NullPointerException, HttpHostConnectException, ConnectException. 어쩌면 Force Close (com.library.UserFunctions.getOrders (UserFunctions.java:71))가 실제로 발생하는 NullPointerException 일 수 있습니다. – YuviDroid

답변

0

당신은 강제 닫기를 얻을. 그것은 문제가됩니다. 왜냐하면 UI가 멈춰서 더듬 거릴 수 밖에 없으므로 Force-Close입니다. 대신 AsyncTask을 사용하십시오.

+0

이를 확인하려면 logcat에서'NetworkActivityOnMainThread' 예외를 확인하십시오. – shkschneider

+0

아니요, 서버 응답 구문 분석과 같이 AsyncTask를 연결로 사용하고 있습니다 ... –

0

이 오류의 3 중요한 라인이 있습니다

Error parsing data org.json.JSONException: End of input at character 0 of 
10-15 18:48:03.759: W/System.err(5061): java.lang.NullPointerException 
10-15 18:48:03.759: W/System.err(5061):  at com.library.UserFunctions.getOrders(UserFunctions.java:71) 

당신은 빈 응답 또는 JSON으로 스레드 할 수없는 이상 반응을 얻을 것으로 보인다. UserFunctions 라인 71을 점검하고 AsyncTask가 충돌없이 비 JSON 결과를 처리 할 수 ​​있는지 확인하십시오.