2017-05-20 6 views
0

私はリクエストがあったときにサーバーがダウンしているかどうかを知りたいが、基本的には単純な登録をしようとしているが(既に動作している)、クリックするとnodeJSサーバーを停止する私が構築する方法に関連する質問についてはボレーのサーバーダウンエラーをキャッチ

public void notifyError(String requestType,VolleyError error) { 
       String body; 
       if(error.networkResponse.data!=null) { 
        String statusCode = String.valueOf(error.networkResponse.statusCode); 
        try { 
         if (error instanceof NetworkError) { 
          Log.d("internet","nao tem internet ligada"); 
         } 
         else if (error instanceof ServerError) { 
          Log.d("internet","The server could not be found. Please try again after some time!!"); 
         } 
         body = new String(error.networkResponse.data,"UTF-8"); 
         JSONObject jsonObj = new JSONObject(body); 
         Log.d("body",String.valueOf(jsonObj.get("message"))); 
         showToast(String.valueOf(jsonObj.get("message"))); 
        } catch (UnsupportedEncodingException e) { 
         showToast("You need to connect to the internet!"); 
        } catch (JSONException e) { 
         Log.d("json:","problems decoding jsonObj"); 
        } 
       } 

:登録し、それは私が見つけいくつかの答えを追跡しようとしましたが、何も私が試したものです。ここ

に動作しない、私のトースト上の任意のエラーが表示されません。私はこれに続くボレーの例をthread

私はNEtworkエラー内のssagesとserverErrorは表示されません。

答えて

0

"if"条件を削除すると、error.networkResponse.dataがnullを返します。 (NetworkError instanceofはエラー){ Log.d( "インターネット"、 "ナオTEMインターネットligada")場合は、意味

public void notifyError(String requestType,VolleyError error) { 
    String body; 
    String statusCode = String.valueOf(error.networkResponse.statusCode); 
    try { 
     if (error instanceof NetworkError) { 
      Log.d("internet","nao tem internet ligada"); 
     } else if (error instanceof ServerError) { 
      Log.d("internet","The server could not be found. Please try again after some time!!"); 
     } 

     body = new String(String.valueOf(error.networkResponse.statusCode),"UTF-8"); 
     JSONObject jsonObj = new JSONObject(body); 
     Log.d("body",String.valueOf(jsonObj.get("message"))); 
     showToast(String.valueOf(jsonObj.get("message"))); 
    } catch (UnsupportedEncodingException e) { 
     showToast("You need to connect to the internet!"); 
    } catch (JSONException e) { 
     Log.d("json:","problems decoding jsonObj"); 
    } 
} 
+0

。 } else if(エラーinstanceof ServerError){ Log.d( "インターネット"、 "サーバーが見つかりませんでした。 } –

+0

(error.networkResponse.data!= null)の –

+0

動作していない、それはログ –

関連する問題