title: Notify changes of Firestore data in RecyclerView
body: <p>In my App there is a fragment that contain an Expandable RecyclerView get data from firebase firestore, every Item  in it have a button that when clicked change some data in Firestore that affect on the items some way. 
  Now the problem is: when run the app and click the button the data don't change till I refresh the fragment..</p>
  
  <p>fragment.java:</p>
  
  <pre><code>View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
  final String UserId = currentUser.getUid();
  
  final RecyclerView recyclerView = root.findViewById(R.id.recyclerview);
  recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
  
  db.collectionGroup("Id").whereEqualTo("id", UserId).get()
    .addOnCompleteListener(new OnCompleteListener &lt; QuerySnapshot &gt; () {
      @Override
      public void onComplete(@NonNull Task &lt; QuerySnapshot &gt; task) {
          final List &lt; Company &gt; Parent = new ArrayList &lt; &gt; ();
  
          for (QueryDocumentSnapshot document: task.getResult()) {
              final List &lt; String &gt; grades = (List &lt; String &gt; ) document.get("tagsG");
  
              CollectionReference collectionReference =
                  document.getReference().getParent();
              final List &lt; Product &gt; Child = new ArrayList &lt; &gt; ();
              for (int i = 0; i &lt; grades.size(); i++) {
                  final String gg = grades.get(i);
                  collectionReference.document(UserId).collection(gg).whereEqualTo("approvedStd",0).get()
                      .addOnCompleteListener(new OnCompleteListener &lt; QuerySnapshot &gt; () {
                          @Override
                          public void onComplete(@NonNull Task &lt; QuerySnapshot &gt; task) {
                              for (QueryDocumentSnapshot document: task.getResult()) {
                                  String name = document.getString("std_name");
                                  String sub = document.getString("std_subject");
                                  String region = document.getString("std_region");
                                  Child.add(new Product(name, sub, region, gg));
                              }
                          }
                      });
              }
              Parent.add(new Company("new", Child));
              productAdapter = new ProductAdapter(Parent);
              recyclerView.setAdapter(productAdapter);
          }
      }
  });
  return root;
  </code></pre>
  
  <p>ViewHolder.java</p>
  
  <pre><code>public class ProductViewHolder extends ChildViewHolder {
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
      private FirebaseAuth mAuth = FirebaseAuth.getInstance();
      private FirebaseUser currentUser = mAuth.getCurrentUser();
      private String UserId = currentUser.getUid();
      private TextView name;
      private TextView sTextView;
      private TextView region;
      private Button addButton;
      private String phoneOfstd;
      private String grade;
      private ProductAdapter productAdapter;
  
      public ProductViewHolder(View itemView) {
          super(itemView);
          name = itemView.findViewById(R.id.name);
          sTextView = itemView.findViewById(R.id.sub);
          region = itemView.findViewById(R.id.region);
      }
  
      public void bind(Product product) {
          name.setText(product.name);
          sTextView.setText(product.sub);
          region.setText(product.region);
          grade = product.grade;
  
          addButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  CollectionReference questionsRef = db.collection("Teachers checked").document("courses").collection("Id");
                  DocumentReference docRef = questionsRef.document(UserId).collection(grade).document(phoneOfstd);
                  docRef.update("approvedStd", 1);
                  productAdapter.notifyDataSetChanged();
              }
          });
      }
  
  }
  </code></pre>
  
  <p>ProductAdapter.java</p>
  
  <pre><code>public class ProductAdapter extends
   ExpandableRecyclerViewAdapter &lt; CompanyViewHolder, ProductViewHolder &gt; {
      public ProductAdapter(List &lt; ? extends ExpandableGroup &gt; groups) {
          super(groups);
      }
  
      @Override
      public CompanyViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.expandable_recyclerview_company, parent, false);
          return new CompanyViewHolder(v);
      }
  
      @Override
      public ProductViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.expandable_recyclerview_product, parent, false);
          return new ProductViewHolder(v);
      }
  
      @Override
      public void onBindChildViewHolder(ProductViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) {
          final Product product = (Product) group.getItems().get(childIndex);
          holder.bind(product);
      }
  
      @Override
      public void onBindGroupViewHolder(CompanyViewHolder holder, int flatPosition, ExpandableGroup group) {
          final Company company = (Company) group;
          holder.bind(company);
      }
  }
  </code></pre>
  
  <p><strong>EDIT :</strong></p>
  
  <p>I tried to write <em>productAdapter.notifyDataSetChanged();</em>  in the fragment after <em>recyclerView.setAdapter(productAdapter);</em> but the app crashes and the logcat shows this error:</p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main  java.lang.NullPointerException: Attempt to
    invoke virtual method 'void 
    com.example.exercise.ExpandableRecyclerView.ProductAdapter. 
    notifyDataSetChanged()' on a null object reference</p>
  </blockquote>