Startlistening In Firebase Ui
Solution 1:
I managed to solve it
instead of :
@OverrideprotectedvoidonStart() {
super.onStart();
adapter.startListening();
}
in MainActivity. Transfer this line adapter.startListening(); inside the loadMenu() before setting the adapter:
adapter.startListening();
recycler_menu.setAdapter(adapter);
Solution 2:
The error you get is:
Attempt to invoke virtual method 'void com.firebase.ui.database.FirebaseRecyclerAdapter.startListening()' on a null object reference at abcd.com.eatme.MainActivity.onStart(MainActivity.java:55)
If you go to line 55 of MainActivity.java that the error mentions, it is in onStart()
:
@OverrideprotectedvoidonStart() {
super.onStart();
adapter.startListening();
}
Specifically adapter.startListening();
is listening, because adapter
doesn't have a value yet.
And indeed, the rest of the code you shared never creates a FirebaseRecyclerAdapter
, so you can't start listening on it. I recommend that you check out the documentation for FirebaseUI, which shows how to create a FirebaseRecyclerAdapter
:
FirebaseRecyclerOptions<Chat> options =
new FirebaseRecyclerOptions.Builder<Chat>()
.setQuery(query, Chat.class)
.build();
FirebaseRecyclerAdapter adapter = newFirebaseRecyclerAdapter<Chat, ChatHolder>(options) {
...
Post a Comment for "Startlistening In Firebase Ui"