I've fetched data from Firebase to the Dashboard (Fragment) Main class , and now I need to access that same ArrayList to another Fragment class. How do i share arraylists between two classes.
My Code from the Dashboard Class:
private void GetCategory() {
DatabaseReference db = FirebaseDatabase.getInstance().getReference("Category");
db.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
Catergory_List cl = userSnapshot.getValue(Catergory_List.class);
CatList.add(cl);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
throw databaseError.toException();
}
});
}
My Second Class
private Dashboard db;
TExpenses= db.TrasactionExpenses();
System.out.println(TExpenses.size());
And i tried this code and its not working
public List<Catergory_List> TrasactionExpenses() {
return CatList;
}
Error Log
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List Dashboard.TrasactionExpenses()' on a null object reference
Any help would be appreciated..i'm unable to get the Values from Dashboard Class ArrayList to Class B