Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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 截击请求总是进入错误侦听器_Java_Android_Json_Listview_Android Fragments - Fatal编程技术网

Java 截击请求总是进入错误侦听器

Java 截击请求总是进入错误侦听器,java,android,json,listview,android-fragments,Java,Android,Json,Listview,Android Fragments,JAVA代码:- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "http://sikkimexpress.itstunner.com/api/homenewslist/topnews", new Response.Listener<JSONObject>() { @Override

JAVA代码:-

 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "http://sikkimexpress.itstunner.com/api/homenewslist/topnews", new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            try {
                                JSONArray jsonArray = response.getJSONArray("HomeNews");

                                for (int i = 0; i<jsonArray.length();i++){
                                    JSONObject homenews = jsonArray.getJSONObject(i) ;

                                    String newsId = homenews.getString("NewsId");
                                    String dateTime = homenews.getString("DateTime");
                                    String newsType = homenews.getString("NewsType");
                                    String title = homenews.getString("Title");
                                    String description = homenews.getString("Description");
                                    String mainImageURL = homenews.getString("MainImageThumbnail");

                                    System.out.println("Result:- " + newsId + " " + dateTime + " " + newsType + " " + title + " " + description + " " + mainImageURL);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    },

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


                            Log.e("VOLLEY", "ERROR");
                        }
                    });


            requestQueue.add(jsonObjectRequest);
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.GET,”http://sikkimexpress.itstunner.com/api/homenewslist/topnews,新的响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONArray JSONArray=response.getJSONArray(“HomeNews”);

对于(inti=0;i我能够得到正确的响应。如果您得到错误,那么记录日志如何

Log.e("VOLLEY", error.getMessage());
一个问题可能是您没有为
JsonObjectRequest
使用正确的构造函数。您最好使用,其中第三个参数
jsonRequest
可以作为null传递

com.android.volley.toolbox.JsonObjectRequest.JsonObjectRequest(int
 method, String url, JSONObject jsonRequest, Listener<JSONObject>
 listener, ErrorListener errorListener)
com.android.volley.toolbox.JsonObjectRequest.JsonObjectRequest(int
方法、字符串url、JSONObject jsonRequest、侦听器
监听器,错误监听器(错误监听器)

否则一切都处于可操作状态。

我能够得到正确的响应。如果您遇到错误,如何记录

Log.e("VOLLEY", error.getMessage());
一个问题可能是您没有为
JsonObjectRequest
使用正确的构造函数。您最好使用,其中第三个参数
jsonRequest
可以作为null传递

com.android.volley.toolbox.JsonObjectRequest.JsonObjectRequest(int
 method, String url, JSONObject jsonRequest, Listener<JSONObject>
 listener, ErrorListener errorListener)
com.android.volley.toolbox.JsonObjectRequest.JsonObjectRequest(int
方法、字符串url、JSONObject jsonRequest、侦听器
监听器,错误监听器(错误监听器)

否则一切都可以正常工作。

url响应是XML而不是JSONI如果你有邮递员,那么你会看到JSON谁告诉你我没有使用邮递员?实际上我使用的是邮递员,它是工作伙伴。你能打印截击错误的内容而不是“错误”吗要真正了解问题所在?url响应是XML而不是JSONI如果你有邮递员,那么你会看到JSON谁告诉你我没有使用邮递员?实际上我使用的是邮递员,它正在工作。你能打印截击错误的内容而不是“错误”吗要真正了解问题所在?嘿,老兄,非常感谢,但我得到了java.net.UnknownHostException。如何解决它?然后你需要
,你说你已经有了,然后另一件事是你自己没有互联网连接。请尝试在浏览器中打开其他网站,看看你是否能够做到。现在它可以了是的,但我不能将列表中的数据设置为空?检查日志您得到了解析的jsonHey Buddy非常感谢,但我得到了java.net.UnknownHostException。如何解决它?然后您将需要
,您说已经有了,然后另一件事是您本身没有internet连接。请尝试打开一些其他的我们B在浏览器中,查看您是否能够做到这一点。现在一切正常,但我无法将列表中的数据设置为空?检查日志您获得了解析的json