title: java.lang.NullPointerException while trying to add data to object of class in Android
body: <p>I am facing a silly problem. I am simply trying to add data to an object of my class, and not succeeding.</p>
  
  <p>I am fetching data via an Asynchronous task inside my fragment and want to use the resulting JSON to fill my ListView. I am using an ArrayAdapter and have created a class for this purpose.</p>
  
  <p>I have parsed the JSON String and now I am trying to add the data retrieved from the API to the object of my class, but it gives me 'java.lang.NullPointerException'.</p>
  
  <p>I guess I am not being able to add data to the object of my class. But I fail to understand the reason, I am more used to cding in C#, but JAVA being Object_Oriented, it should be the same, right? The code being used is as below...</p>
  
  <pre><code>    JSONArray jsonArrayPendingBills = new JSONArray();
      jsonArrayPendingBills = jsonObjectPendingBills.getJSONArray(TAG_RESPONSE_MESSAGE);
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; arrayPendingBills = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
      ArrayList&lt;PendingBills&gt; arrayClassPendingBills = new ArrayList&lt;PendingBills&gt;();
  
      for(int i = 0;i &lt; jsonArrayPendingBills.length(); i++){
          JSONObject jsonObjectPendingBill = jsonArrayPendingBills.getJSONObject(i);
  
          String strDate = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_DATE);
          String strTxCode = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_TX_CODE);
          String strFromAccount = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_FROM_ACCOUNT);
          String strAmount = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_AMOUNT);
          String strDetails = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_DETAILS);
          String strBillCode = jsonObjectPendingBill.getString(TAG_PENDING_BILLS_BILL_CODE);
  
          PendingBills objPendingBills = new PendingBills();
          objPendingBills.setBillAmount(strAmount);
          objPendingBills.setBillDate(strDate);
          objPendingBills.setBillName(strFromAccount);
          //arrayClassPendingBills.add(new PendingBills(strAmount, strDate, strFromAccount));
          arrayClassPendingBills.add(objPendingBills);
      }
  
      PendingBillsAdapter pendingBillsAdapter = new PendingBillsAdapter(getActivity(), R.layout.pending_bills_list_view_row, arrayClassPendingBills);
      listViewPendingBills.setAdapter(pendingBillsAdapter);
  
      progressDialogPendingBills.dismiss();
  }
  catch (Exception e){
      e.printStackTrace();
      Log.i("Error", "Error", e);
  }
  </code></pre>
  
  <p>This is the code for my class:</p>
  
  <pre><code>public class PendingBills {
  
      // Declaring the strings for the class
      public String BillAmount;
      public String BillDate;
      public String BillName;
  
      // Writing down the constructor for this class  
      public PendingBills(String BillAmount, String BillDate, String BillName){
          this.BillAmount = BillAmount;
          this.BillDate = BillDate;
          this.BillName = BillName;
      }
  
      public PendingBills(){
  
      }
  
      // Getter for BillAmount
      public String getBillAmount(){
          return BillAmount;
      }
  
      // Setter for BillAmount
      public void setBillAmount(String BillAmount){
          this.BillAmount = BillAmount;
      }
  
      public String getBillDate(){
          return BillDate;
      }
  
      public void setBillDate(String BillDate){
          this.BillDate = BillDate;
      }
  
      public String getBillName(){
          return BillName;
      }
  
      public void setBillName(String BillName){
          this.BillName = BillName;
      }
  
  }
  </code></pre>
  
  <p>I think I am missing something. I am not sure what? I have looked up a few questions on StackOverflow relating to this. I found many of them, but the solutions did not work for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/13670403/adding-data-to-an-array-list">Adding data to an array list</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18388629/how-to-properly-add-data-to-arraylist-android">How to properly add data to ArrayList - Android</a></p>
  
  <p>Any help will be appreciated. Thank you.</p>
  
  <p>Here is the LogCat....</p>
  
  <pre><code>12-02 07:02:04.235: E/AndroidRuntime(4648): FATAL EXCEPTION: main
  12-02 07:02:04.235: E/AndroidRuntime(4648): java.lang.NullPointerException
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at com.zipcash.zipcashbetaversion.PendingBillsAdapter.getView(PendingBillsAdapter.java:43)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.AbsListView.obtainView(AbsListView.java:2159)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.ListView.onMeasure(ListView.java:1158)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1029)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.View.measure(View.java:15518)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.Choreographer.doFrame(Choreographer.java:532)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.os.Handler.handleCallback(Handler.java:725)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.os.Handler.dispatchMessage(Handler.java:92)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.os.Looper.loop(Looper.java:137)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  12-02 07:02:04.235: E/AndroidRuntime(4648):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>