Skip to content
Advertisement

Android studio – Java Null-pointer on Firebase invocation

The actual error I receive when running the program is:

java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.DatabaseReference.child(java.lang.String)' on a null object reference

This is my firebase database class:

JavaScript

This is my main class:

JavaScript

I’ve attempted different solutions but I still receive nullPointerException for the database. How could I properly initialize the database for access?

I would really appreciate the help on this. Thank you for any advice given.

Advertisement

Answer

I found problem in your code. Your error is occurred when call child method of mReferenceCrossings.

JavaScript

Because mReferenceCrossings is null. mReferenceCrossings will be assigned in following method of your code.

JavaScript

But I don’t find any part this method calling in your main class. You just called sort method without creating FirebaseDatabaseHelper. So your code have error.

JavaScript

}

EDIT: update for solution.

Solution is several ways.
Here is one of those.
So you need to update FirebaseDatabaseHelper like this.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement