This is my code, I'm using volley to call a web service
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);
}
Anything wrong, getting NullPointerException
URL:
ShowJson method
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);
}
Parse JSON class
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();
}
}
}