Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在实现JsonObjectRequest时遇到问题_Java_Android_Json - Fatal编程技术网

Java 在实现JsonObjectRequest时遇到问题

Java 在实现JsonObjectRequest时遇到问题,java,android,json,Java,Android,Json,我在实现JsonObjectRequest以从web访问JsonObject时遇到问题。 我正在尝试创建一个新的JsonObjectRequest: JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override

我在实现JsonObjectRequest以从web访问JsonObject时遇到问题。 我正在尝试创建一个新的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) {

        }
    });
JsonObjectRequest-JsonObjectRequest=new-JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONObject ratesJsonObj=response.getJSONObject(“rates”);
字符串RON=ratesJsonObj.getString(“RON”);
Log.v(“货币”,RON);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});
但所有的东西都是扭曲的,安卓工作室用红色标注了一个不高的等级,上面写着

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
错误:(41,47)错误:对JsonObjectRequest的引用不明确,两个构造函数
JsonObjectRequest(int、String、String、Listener、ErrorListener)
在JsonObjectRequest和构造函数中
JSONObject请求(int、字符串、JSONObject、侦听器、ErrorListener)
在JsonObjectRequest中匹配
有人知道怎么回事吗?

试着这样做:

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) {

    }
});
JsonObjectRequest-JsonObjectRequest=newjsonobjectrequest(Request.Method.GET,url,(JSONObject)null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONObject ratesJsonObj=response.getJSONObject(“rates”);
字符串RON=ratesJsonObj.getString(“RON”);
Log.v(“货币”,RON);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});
尝试以下方法:

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) {

    }
});
JsonObjectRequest-JsonObjectRequest=newjsonobjectrequest(Request.Method.GET,url,(JSONObject)null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONObject ratesJsonObj=response.getJSONObject(“rates”);
字符串RON=ratesJsonObj.getString(“RON”);
Log.v(“货币”,RON);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});

将null强制转换为字符串,它将正常工作。(String)null

将null转换为String,它将工作。(字符串)null

坦克很多@Oleg Khalidov。。。小演员们阻止了我:)坦克很多@Oleg Khalidov。。。那个小小的演员让我退缩了:)