gpt4 book ai didi

java - 没有得到响应 Volley android

转载 作者:行者123 更新时间:2023-11-29 19:45:55 25 4
gpt4 key购买 nike

<分区>

enter image description here这是我的代码,我正在使用 volley 来调用网络服务

private void sendRequest(){

StringRequest stringRequest = new StringRequest(JSON_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);


}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.getMessage(),Toast.LENGTH_LONG).show();
}
});

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}

任何错误,得到 NullPointerException

网址:

https://www.bgr.ionidea.com/math_lms/webservice/rest/server.php?wstoken=840e7d1cb52ca12239b01926310e0c68&wsfunction=local_math_get_android_version&moodlewsrestformat=json

ShowJson 方法

 private void showJSON(String json){
ParseJSON pj = new ParseJSON(json);
pj.parseJSON();
CustomList cl = new CustomList(this, ParseJSON.id,ParseJSON.app_version);
listView.setAdapter(cl);
}

解析JSON类

public class ParseJSON {

public static String[] id;
public static String[] app_version;


public static final String JSON_ARRAY = "result";
public static final String KEY_ID = "id";
public static final String KEY_APP_VERSION = "app_version";


private JSONArray users = null;

private String json;

public ParseJSON(String json){
this.json = json;
}

protected void parseJSON(){
JSONObject jsonObject=null;
try {
jsonObject = new JSONObject(json);
users = jsonObject.getJSONArray(JSON_ARRAY);

id = new String[users.length()];
app_version = new String[users.length()];


for(int i=0;i<users.length();i++){
JSONObject jo = users.getJSONObject(i);
id[i] = jo.getString(KEY_ID);
app_version[i] = jo.getString(KEY_APP_VERSION);

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com