title: Android: notifyDataSetChanged() to refresh my ListView
body: <p>I am getting a NullPointer exception when getting a method from a class to refresh my ListView. I am calling a method from a fragment inside an adapter's onclick event. Mostly every thing is working well, I just cant refresh the listview after entering new items/row in it.</p>
  
  <pre><code>public class Cashier extends Fragment {
      public SaleAdapter saleAdapter;
      List&lt;SaleModel&gt; saleModelList = new ArrayList&lt;&gt;()
  
      public view onCreateView(...) {
          load_sales();
      }
  
      public void load_sales() {
          saleModelList.clear();
          SQLiteHelper db = new SQLiteHelper(getActivity());
          Cursor cursor = db.showSales();
          if(cursor.moveToFirst()) {
              do {
                  SaleModel saleModel = new SaleModel(            
  cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PCODE)),
  cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_QUANTITY)),
  cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_SRP)),
  cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_TOTALPRICE))
                  );
                  saleModelList.add(saleModel);
              } while(cursor.moveToNext());
          }
      saleAdapter = new SaleAdapter(getActivity(), R.layout.list_sale, saleModelList);
      lvSales.setAdapter(saleAdapter);
      saleAdapter.notifyDataSetChanged();
      }
  
      public void refreshList() {
          saleAdapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>From an Adapter I have to call the load_sales() method.</p>
  
  <pre><code>public class ProductAdapter extends RecycleView.Adapter .... {
      private List&lt;ProductModel&gt; productModelList = new ArrayList&lt;&gt;();
      private Context context;
  
      public ProductAdapter (Context context, List&lt;ProductModel&gt; productModelList) {
          this.context = context;
          this.productModelList = productModelList;
      }
  
      class HolderData extends RecycleView.ViewHolder {
          ...
          view.OnClickListener(....) {
              AlertDialog.Builder builder = ....
              builder.setPositiveButton() {
                  Cashier cashier = new Cashier();  //Declare cashier as new Cashier class
                  cashier.refreshList();  //Uses the refreshList() to reload the ListView
              }
          }
      }
  }
  </code></pre>
  
  <p>Here is my error </p>
  
  <pre><code>java.lang.NullPointerException
      at xxxx.fragment.Cashier.refershList(Cashier.java:112)
      at xxxx.utility.adapter.ProductAdapter$HolderData$1$1.onClick(ProductAdapter.java:121)
      at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161)
  </code></pre>