I have a list that is being used by two separate classes. I need this list to be defined in one of my onDataChange methods however, and this is giving me some issues. At the top of my class I have my list defined as this:
public List<String> openGames; I have that there so my RecyclerView class can use it. I then initialize my list in an onDataChange method like this
public void updateUI(final ListCallback callBack) { FCGames.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { numGames = (int) dataSnapshot.getChildrenCount(); openGames = new ArrayList<>(); . . . Those dots are there just to say there is more code, but I don't think it is necessary for this problem.
In MyRecyclerViewer class, this list is being used and when the Activity opens it tries to get the size of the list like this:
@Override public int getItemCount() { return mData.size(); } But since the list is not defined until some things in my app occur, like the onDataChange method being called upon, this throws me an error:
Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
I know the cause of this is because the list is not defined before the size of the list is taken.
So what I have done to try to get around this is adding a null list size check when it takes the list size, and that does get rid of the error, but it makes my entire RecyclerViewer not function at all
Are there any work around for this?