title: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Iterator java.util.ArrayList
body: <p>I'm currently working on an android app to fetch data from the server. It crashes and I get a <code>NullPointerException</code>. Can anyone help me edit my code/ list out my error? </p>
  
  <p>Here is my code (I have read a through few of the forums but did not really understand how to solve my problem)</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ListView lvPost;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lvPost = (ListView)findViewById(R.id.lvPost);
  
          String url2 = "http://192.168.0.146/client/login.php?format=json";
          PostResponseAsyncTask task2 = new PostResponseAsyncTask(MainActivity.this, new AsyncResponse() {
              @Override
              public void processFinish(String s) {
                  ArrayList&lt;Post&gt; postList =
                          new JsonConverter&lt;Post&gt;().toArrayList(s, Post.class);
  
                  ArrayList&lt;String&gt; titles = new ArrayList&lt;String&gt;();
  
                  for (Post value:postList) {
                      titles.add(value.post_title);
                  }
  
                  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(MainActivity.this,
                          android.R.layout.simple_list_item_1, titles);
  
                  lvPost.setAdapter(adapter);
              }
          });
  
          task2.execute(url2);
      }
  }
  </code></pre>
  
  <p>Here is my logcat</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method       'java.util.Iterator java.util.ArrayList.iterator()' on a null object reference
       at com.example.1231.t12.MainActivity$1.processFinish(MainActivity.java:40)
       at com.kosalgeek.genasync12.PostResponseAsyncTask.onPostExecute(PostResponseAsyncTask.java:188)
       at com.kosalgeek.genasync12.PostResponseAsyncTask.onPostExecute(PostResponseAsyncTask.java:27)
       at android.os.AsyncTask.finish(AsyncTask.java:632)
       at android.os.AsyncTask.access$600(AsyncTask.java:177)
       at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6075)
       at java.lang.reflect.Method.invoke(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  </code></pre>