2016-08-02 3 views
0

次のイベントは、Androidのボタンをクリックしたときにトリガーされ、paramsでレールサーバーに投稿要求を行います。過去に同じコードが動作していたようだが、今は何が間違っていたのか分からない。
デバッグでは、カーソル/コントロールがJSONObject-jsの作成からJsonObjectRequest jsonObjReq = new JsonObjectRequest(...)、次にqueue.add(jsonObjReq)に移動します。 次のエラーメッセージが現れます: - Androidのスタジオモニターで のメッセージ - D /ボレー:[1] 2.onErrorResponse:ShoppingCartActivityJSON Object volley投稿要求 - サーバーに到達できません - レール192.168.0.3にバインドされたローカルURL

どれ/すべての提案は歓迎されています。ここ

コード: -

bCheckOut.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 
final String LOGIN_URL = "http://192.168.0.3:3000/shopping/cart_items"; 

       RequestQueue queue = Volley.newRequestQueue(ShoppingCartActivity.this); 
       final String access_token = "sWbxDJrF6SrB+DdWXLavoBz2LjiA5QCns5S6DMb7N4rDTWuHfcVYQ/1HxwHOq2fw7xXU4pXAjFw==“; //test purposes. 
       Log.d(TAG, "Shopping cart item list: " + " Shopping cart items . " + LOGIN_URL); 
       JSONObject js = new JSONObject(); 
       try { 
        JSONObject jsonobject_one = new JSONObject(); 

        jsonobject_one.accumulate("variant_id", "4217"); 
        jsonobject_one.accumulate("quantity", "1"); 

        JSONObject jsonobject_TWO = new JSONObject(); 
        jsonobject_TWO.accumulate("authenticity_token", access_token); 
        jsonobject_TWO.accumulate("utf8", "tick"); 
        jsonobject_TWO.accumulate("name", "Rakesh"); 

        JSONObject jsonobject = new JSONObject(); 

        jsonobject.accumulate("requestinfo", jsonobject_TWO); 
        js.accumulate("authenticity_token", access_token); 
        js.accumulate("utf8", "tick"); 
        js.accumulate("name", "Rakesh"); 
        js.accumulate("cart_item", jsonobject_one); 

        //js.accumulate("Parameters", jsonobject); 

       }catch (JSONException e) { 
        e.printStackTrace(); 
       } 

       JsonObjectRequest jsonObjReq = new JsonObjectRequest(
         Request.Method.POST,LOGIN_URL, js, 
         new Response.Listener<JSONObject>() { 
          @Override 
          public void onResponse(JSONObject response) { 
           Log.d(TAG, response.toString()); 

           //msgResponse.setText(response.toString()); 
           //hideProgressDialog(); 
          } 
         }, new Response.ErrorListener() { 

        @Override 
        public void onErrorResponse(VolleyError error) { 
         VolleyLog.d(TAG, "Error: " + error.getMessage()); 
         //hideProgressDialog(); 
        } 
       }) { 

        /** 
        * Passing some request headers 
        */ 
        @Override 
        public Map<String, String> getHeaders() throws AuthFailureError { 
         HashMap<String, String> headers = new HashMap<String, String>(); 
         headers.put("Content-Type", "application/json; charset=utf-8"); 
         return headers; 
        } 
       }; 
       //ApplicationController.getInstance().addToRequestQueue(postRequest); 
       queue.add(jsonObjReq); 

      } 
     }); 

答えて

0

問題などが解決されているように私は、この質問への応答を掲示しています。実際には、システムとAndroidスタジオを再起動/再起動するのはやりました。私はデバイスからアプリケーションを閉じ、Androidのスタジオを閉じ、システム全体を閉じた/再起動した。 特定のIPアドレスでレールサーバーを再起動し、アプリケーションを再起動し、アンドロイドデバイスからRailsサーバーに要求が正常に送信されています。誰か他の人が同じ問題に直面した場合や、立ち往生しているように見える場合は、役立つ可能性があります。ありがとう。

関連する問題