LoginSignup
9
9

More than 5 years have passed since last update.

エラー: JsonObjectRequestの参照はあいまいです。

Last updated at Posted at 2015-03-18

volleyでJSONの処理したい時に、以下のような記述で動作していたアプリがAndroidStudioでタイトルのようなエラーを出すようになりました。

String api_url = "http://test.com";
JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.GET,api_url,null,
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject jsonObject) {
            // 処理
        }
    },
    new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error){
            //
        }
    }
);

昨日の朝まではエラーも出ずに問題なかったんですけれど。

エラー: JsonObjectRequestの参照はあいまいです。
JsonObjectRequestのコンストラクタ JsonObjectRequest(int,String,String,Listener,ErrorListener)
とJsonObjectRequestのコンストラクタ JsonObjectRequest(int,String,JSONObject,Listener,ErrorListener)
が両方適合します

というエラーメッセージでした。
なぜ今まではエラーが出なかったのか、理由はわかりません。

http://afzaln.com/volley/com/android/volley/toolbox/JsonObjectRequest.html
コンストラクタには上記の他にリクエストメソッドの引数が無いコンストラクタも定義されていたので、これでも問題無い自分の環境では

String api_url = "http://test.com";
JsonObjectRequest jsonRequest = new JsonObjectRequest(api_url,null,
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject jsonObject) {
            // 処理
        }
    },
    new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error){
            //
        }
    }
);

とすることでエラーを回避できました。

9
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9