2016-05-12 7 views
0

JsonObjectRequestを実装する際に問題が発生しました。JsonObjectウェブから。 私は新しいJsonObjectRequest作成しようとしています:JsonObjectRequestを実装する際に問題が発生しました。

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        try { 

         JSONObject ratesJsonObj = response.getJSONObject("rates"); 
         String RON = ratesJsonObj.getString("RON"); 

         Log.v("Currency", RON); 

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

       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 

     } 
    }); 

をしかし、それがすべてだすべてが波線の下でアンドロイドのスタジオで、赤とhighlited、それは

Error:(41, 47) error: reference to JsonObjectRequest is ambiguous, both constructor 
JsonObjectRequest(int,String,String,Listener<JSONObject>,ErrorListener) 
in JsonObjectRequest and constructor 
JsonObjectRequest(int,String,JSONObject,Listener<JSONObject>,ErrorListener) 
in JsonObjectRequest match 

を言う誰もが間違って何任意のアイデアを持っていますか?

答えて

2

は、この方法を試してみてください。

文字列にnullをキャスト
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, (JSONObject) null, 
     new Response.Listener<JSONObject>() { 
      @Override 
      public void onResponse(JSONObject response) { 
       try { 

        JSONObject ratesJsonObj = response.getJSONObject("rates"); 
        String RON = ratesJsonObj.getString("RON"); 

        Log.v("Currency", RON); 

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

      } 
     }, new Response.ErrorListener() { 
    @Override 
    public void onErrorResponse(VolleyError error) { 

    } 
}); 
+0

タンクがたくさん@Oleg Khalidov ... thtat小さなキャスト私を保持する:) – Adrian

0

、それが動作します。 (文字列)null

関連する問題