Null pointer exception during ParseJSON : <p>When i am trying to parse the json, its throwing a null pointer exception. Also nothing is showing when i am trying to display the values.</p>

<p>code:</p>

<pre><code>public class ParseJSON {
    //public static String[] ids;
    public static String[] names;
    public static String[] message;

    public static final String JSON_ARRAY = "users";
   // public static final String KEY_ID = "id";
    public static final String KEY_NAME = "username";
    public static final String KEY_EMAIL = "message";

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

            //final String TAG = events.class.getSimpleName();
            //Log.d(TAG, "username value: \n" + KEY_NAME);


            for(int i=0;i&lt;users.length();i++){
                JSONObject jo = users.getJSONObject(i);
               // ids[i] = jo.getString(KEY_ID);
                names[i] = jo.getString(KEY_NAME);
                message[i] = jo.getString(KEY_EMAIL);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
} 
</code></pre>

<p>but when i am trying to display the the parse values, i am displaying it in a separate page, there if i can try to display values using LOG.d, it is showing values.</p>

<p>list_view.java</p>

<pre><code>   private void sendRequest(){


        StringRequest stringRequest = new StringRequest(JSON_URL,
                new Response.Listener&lt;String&gt;() {



                    @Override
                    public void onResponse(String response) {
                        showJSON(response);
                    }
                },


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

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




    private void showJSON(String json){

       final String TAG = events.class.getSimpleName();
       Log.d(TAG, "showJSON: \n" + json);

        ParseJSON pj = new ParseJSON(json);
        pj.parseJSON();
        CustomList cl = new CustomList(this,ParseJSON.names,ParseJSON.message);
        listView.setAdapter(cl);
    }

    @Override
    public void onClick(View v) {
        sendRequest();
    }
}
</code></pre>

<p>Here is the error;</p>

<pre><code>04-24 21:49:39.449 15992-15992/? D/events: showJSON: 
                                           {"users":[{"username":"varun","message":"hello word, my first message "},{"username":"varun","message":"hello word, my first message "},{"username":"rahul","message":"hello world"},{"username":"rahul","message":"world: its cool"},{"username":"rahul","message":"awesom"},{"username":"rahul","message":"ranom"},{"username":"rahul","message":"randimagain"},{"username":"rahi","message":"is it me again"},{"username":"rahull","message":"hi rahul"},{"username":"rahul","message":"world, am bacj"},{"username":"rahul","message":"hello parents"},{"username":"","message":""},{"username":"","message":""},{"username":"","message":""},{"username":"","message":""},{"username":"","message":""},{"username":"varun","message":"google world"},{"username":"rahul","message":"ollaaa"},{"username":"rahul","message":"ollaaa"},{"username":"rahul","message":"where are others"},{"username":"rahul","message":"where are others"},{"username":"varun","message":"oil spil"},{"username":"varun","message":"phone"},{"username":"vatun","message":"tttt"},{"username":"varun","message":"poiuytrew"},{"username":"rahui","message":"yregh"},{"username":"varun","message":"huiokgddfv"},{"username":"rahi","message":"poiutghklnbfd"},{"username":"rahui","message":"qwerty"},{"username":"varub","message":"hi eat pineapple"},{"username":"varun","message":"hi prabh"},{"username":"rahul","message":"hi world"},{"username":"ggjdjjf","message":"yhvdhhj"},{"username":"tgggg","message":"hhhh"},{"username":"rahul","message":"lqvrl"},{"username":"hhhh","message":"ghh"},{"username":"tff","message":"gg"},{"username":"hfdhn","message":"hnnnme"},{"username":"popo","message":"plpl"},{"username":"rahulpop","message":"op music"},{"username":"rtrt","message":"tyty"},{"username":"hlpo","message":"opop"},{"username":"hlpoghhj","message":"opop"},{"username":"tt","message":"hhh"},{"username":"ttere","message":"hhh"},{"username":"gytgjyg","message":"lajdhd"},{"username":"topo","message":"ptpt"},{"username":"jgj","message":"rtr"},{"username":"ry","message":"yr"},{"username":"ry","message":"yr"},{"username":"y","message":"q"},{"username":"u","message":"t"},{"username":"tt","message":"pp"},{"username":"q","message":"z"},{"username":"w","message":"v"},{"username":"e","message":"e."},{"username":"ui","message":"ui"},{"username":"yi","message":"yi"},{"username":"gg","message":"g"},{"username":"e","message":"e"},{"username":"h","message":"hh"},{"username":"j","message":"j"},{"username":"j","message":"k"},{"username":"v","message":"v"}]}
04-24 21:49:39.459 15992-15992/? D/AndroidRuntime: Shutting down VM
04-24 21:49:39.459 15992-15992/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40c1ea68)
04-24 21:49:39.529 15992-15992/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   java.lang.NullPointerException
                                                       at com.weavearound.schools.weavearound.ParseJSON.parseJSON(ParseJSON.java:43)
                                                       at com.weavearound.schools.weavearound.list_view.showJSON(list_view.java:76)
                                                       at com.weavearound.schools.weavearound.list_view.access$000(list_view.java:22)
                                                       at com.weavearound.schools.weavearound.list_view$1.onResponse(list_view.java:51)
                                                       at com.weavearound.schools.weavearound.list_view$1.onResponse(list_view.java:45)
                                                       at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
                                                       at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
                                                       at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
                                                       at android.os.Handler.handleCallback(Handler.java:605)
                                                       at android.os.Handler.dispatchMessage(Handler.java:92)
                                                       at android.os.Looper.loop(Looper.java:137)
                                                       at android.app.ActivityThread.main(ActivityThread.java:4517)
                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
                                                       at dalvik.system.NativeStart.main(Native Method)
04-24 21:49:39.559 403-420/? E/android.os.Debug: !@Dumpstate &gt; dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
</code></pre>
