Fatal Exception: Invalid index 0,out of 0 : <p>I'm trying to retrieve the json data with JsonArrayRequest and then add it to a list. Here's my code</p>

<pre><code>public class QuestionDetailFragment extends Fragment {
    RecyclerView cRecyclerView;
    private static final String url = "http://10.0.2.2:80/forumtest/readquestion.php?format=json";
    private List&lt;String&gt; userList = new ArrayList&lt;&gt;();
    RequestQueue requestQueue;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.question_details_layout, container, false);
        readQuestionDetails();

        Log.d("check", "data:" + userList.get(0));

        return view;
    }

    private void readQuestionDetails() {
        Log.d("Volley", "Called222!");
        requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, url, new Response.Listener&lt;JSONArray&gt;() {
            @Override
            public void onResponse(JSONArray response) {

                try {
                    for (int i=0;i&lt;response.length();i++) {
                        JSONObject jsonObject = response.getJSONObject(i);

                        userList.add(jsonObject.getString("user"));

                            }

                } catch (JSONException e) {
                    e.printStackTrace();
                    Log.e("tag",e.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Volley", error.getMessage());

            }
        });


        requestQueue.add(jsonArrayRequest);
    }

}
</code></pre>

<p>I've used <strong><em>Log.d("user`,"data:",user.get(0));</em></strong> just to make sure that the data has been added to the list. This is my logcat after running the code</p>

<pre><code>    03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime: FATAL EXCEPTION: main
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime: Process: com.rekoj.softwarica, PID: 2767
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at java.util.ArrayList.get(ArrayList.java:308)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at com.rekoj.softwarica.Forum.QuestionDetailFragment.onCreateView(QuestionDetailFragment.java:50)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-08 20:45:25.750 2767-2767/com.rekoj.softwarica E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-08 20:50:25.802 2767-2767/? I/Process: Sending signal. PID: 2767 SIG: 9
</code></pre>
