martiendt martiendt -4 years ago 98
Android Question

cannot be converted to DatabaseReference

I try to filter the database of firebase, but i got this error

Error:(26, 107) error: incompatible types: Query cannot be converted to DatabaseReference


this is my code, it's running well if i remove
.startAt("test")


DatabaseReference listRef = FirebaseDatabase.getInstance()
.getReference("question-answer")
.startAt("test");`


i'm using Firebase RecycleViewAdapter and i want to filter that view, how to achive this ?

github repo : https://github.com/martiendt/daily-dhamma

class = https://github.com/martiendt/daily-dhamma/blob/master/app/src/main/java/red/point/dailydhamma/ListFragment.java

Answer Source

Error:(26, 107) error: incompatible types: Query cannot be converted to DatabaseReference

You can check in the official documentation.
The method startAtreturns a Query not a DatabaseReference.

You have to use:

Query listRef = FirebaseDatabase.getInstance()
   .getReference("question-answer")
   .startAt("test");

You can use your RecyclerView by passing a Query instead of a normal DatabaseReference.

Query listRef = ....;
mAdapter = new FirebaseRecyclerAdapter<XX, XXViewHolder>(XX.class,
            R.layout.xxx_recycler_item, EXXViewHolder.class, listRef) { ... }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download