title: Null pointer Exception in asynctask
body: <p>Please help me why i'm getting this error.
  I'm getting Json response converting into string using <code>convertStreamToString</code> method getting correct string, I can able to see this string in my logcat.<br>
  Now i'm trying to insert my json response string to sqlite database, for that i'm using </p>
  
  <pre><code>JSONObject HabitatObject = MyHabitatJsonObject.getJSONObject("HabitatDetails");    
  JSONObject HabitatPosts = HabitatObject.getJSONObject("habitat");
      JSONArray HabitatPostsArray = HabitatPosts.getJSONArray("Post");
          ContentValues values = new ContentValues();
           DatabaseHelper InsertHabitat;     
          for (int i = 0; i &lt; HabitatPostsArray.length(); i++) {
           values.put(InsertHabitat.PostUserImage, HabitatPostsArray.getJSONObject(i).getString("userimage").toString());
           values.put(InsertHabitat.PostUserName, HabitatPostsArray.getJSONObject(i).getString("username").toString());
      dbHabitat.insert(InsertHabitat.HABITATTABLE, null, values);
                  }
  </code></pre>
  
  <p>Till now every thing is fine but when i'm trying to insert these values into database i'm getting error on this line <br><code>values.put(InsertHabitat.PostUserImage, HabitatPostsArray.getJSONObject(i).getString("userpostimage").toString());</code></p>
  
  <p>Error Log:</p>
  
  <pre><code>12-10 10:57:19.872: E/AndroidRuntime(301): FATAL EXCEPTION: AsyncTask #3
  12-10 10:57:19.872: E/AndroidRuntime(301): java.lang.RuntimeException: An error occured while executing doInBackground()
  12-10 10:57:19.872: E/AndroidRuntime(301):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.lang.Thread.run(Thread.java:1096)
  12-10 10:57:19.872: E/AndroidRuntime(301): Caused by: java.lang.NullPointerException
  12-10 10:57:19.872: E/AndroidRuntime(301):  at com.UserLogin.Habitat$HabitatResults.doInBackground(Habitat.java:90)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at com.UserLogin.Habitat$HabitatResults.doInBackground(Habitat.java:1)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
  12-10 10:57:19.872: E/AndroidRuntime(301):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  12-10 10:57:19.872: E/AndroidRuntime(301):  ... 4 more
  </code></pre>