Null browser and postman中的响应为200 ok,并以JSON格式显示所有数据,但volley给出的错误代码为空 private void fetchData(){ 字符串topheadlinesURL=”https://api.mediast
browser and postman中的响应为200 ok,并以JSON格式显示所有数据,但volley给出的错误代码为空Null browser and postman中的响应为200 ok,并以JSON格式显示所有数据,但volley给出的错误代码为空 private void fetchData(){ 字符串topheadlinesURL=”https://api.mediast,null,android-volley,Null,Android Volley,browser and postman中的响应为200 ok,并以JSON格式显示所有数据,但volley给出的错误代码为空 private void fetchData(){ 字符串topheadlinesURL=”https://api.mediastack.com/v1/news?access_key=3c265259628c0c7253f0e8ef173ec25b"; StringRequest=new StringRequest(request.Method.GET、topheadli
private void fetchData(){
字符串topheadlinesURL=”https://api.mediastack.com/v1/news?access_key=3c265259628c0c7253f0e8ef173ec25b";
StringRequest=new StringRequest(request.Method.GET、topheadlinesURL、new Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Toast.makeText(MainActivity.this,“this”+响应,Toast.LENGTH_SHORT.show();
试一试{
JSONObject JSONObject=新JSONObject(响应);
//........
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
NetworkResponse=错误。NetworkResponse;
字符串errorMsg=“”;
if(response!=null&&response.data!=null){
String errorString=新字符串(response.data);
Log.i(“日志错误”,errorString);
}
Toast.makeText(MainActivity.this,“找不到数据!!!”+error.getMessage(),Toast.LENGTH\u SHORT.show();
}
});
RequestQueue RequestQueue=Volley.newRequestQueue(this);
setRetryPolicy(新的DefaultRetryPolicy(10000,1,1.0f));
添加(请求);
}
private void fetchData() {
String topheadlinesURL = "https://api.mediastack.com/v1/news?access_key=3c265259628c0c7253f0e8ef173ec25b";
StringRequest request = new StringRequest(Request.Method.GET, topheadlinesURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "this "+response, Toast.LENGTH_SHORT).show();
try {
JSONObject jsonObject = new JSONObject(response);
//........
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse response = error.networkResponse;
String errorMsg = "";
if(response != null && response.data != null){
String errorString = new String(response.data);
Log.i("log error", errorString);
}
Toast.makeText(MainActivity.this, "Data Not Found !!!"+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f));
requestQueue.add(request);
}