2017-09-02 9 views
0

を使用する場合JsonObjectRequestエラーが見つかりません適切なコンストラクタ -サーバは、以下のJSON返しボレー

[ { "USER_ID":1、 "FIRST_NAME": "アレックス"、 "姓" を: "goft"、 "パスワード": "doom00"、 "電子メール": "[email protected]"、 "ユーザー名": "alexgoft" } ]

私は次の関数でボレーを使用してそれを取得しようと -

public void makeRequest() { 
     final String HOST = "http://10.0.2.2:3000/"; 
     final String url = HOST + "get_data?type=user&username=alexgoft"; 
     RequestQueue queue = Volley.newRequestQueue(context); 

     Toast.makeText(context, url, Toast.LENGTH_LONG).show(); 

     // prepare the Request 
     JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, 
       new Response.Listener<JSONArray>() { 
        @Override 
        public void onResponse(JSONArray response) { 
         Toast.makeText(context, "In succ", Toast.LENGTH_LONG).show(); 
         try { 
          returned_json = response.getJSONObject(0); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Toast.makeText(context, "In error", Toast.LENGTH_LONG).show(); 
         Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show(); 
         error.getStackTrace(); 
         Log.d("error", error.toString()); 
        } 
       }); 

     queue.add(getRequest); 
    } 

問題は、私は次のエラーを取得することである -

Error:(46, 40) error: no suitable constructor found for JsonObjectRequest(int,String,<anonymous Listener<JSONArray>>,<anonymous ErrorListener>) 
constructor JsonObjectRequest.JsonObjectRequest(int,String,Listener<JSONObject>,ErrorListener) is not applicable 
(argument mismatch; <anonymous Listener<JSONArray>> cannot be converted to Listener<JSONObject>) 
constructor JsonObjectRequest.JsonObjectRequest(String,JSONObject,Listener<JSONObject>,ErrorListener) is not applicable 
(argument mismatch; int cannot be converted to String) 

私はそうreturned_jsonが返されたJSONが含まれていることを行うためには何が必要なのかホストから?

これは、IDEで見えた方法です -

enter image description here

+0

コンパイル時にエラーが発生した場合、どのように応答が返されますか? –

答えて

1

:あなたの参考のため

あなたの応答があるのでJSONArrayはそうあなたが実装する必要があります代わりとしても@Krupa Kakkad

new JsonObjectRequest(Request.Method.GET, url, null, 
//           ^^^^ 
       new Response.Listener<JSONArray>() { 

From Docs

によって指し示さ JsonObjectRequest
@param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and 
    * indicates no parameters will be posted along with request. 

コンストラクタ署名

公共JsonObjectRequest(INT法、文字列のURL、JSONObject jsonRequest、 リスナーリスナーは、ErrorListenerは、ErrorListener){

又は

公共JsonObjectRequest (String url、JSONObject jsonRequest、 リスナー・リスナー ErrorListener errorListener){

関連する問題