Dominic Dominic - 1 year ago 118
Android Question

Android Firebase: Can´t add ValueEventListener

database = FirebaseDatabase.getInstance();
myRef = database.getReference("lifts");

Why can't I add the ValueEventListener? I tried the sample from the Firebase Guide.

myRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {


public void onCancelled(FirebaseError firebaseError) {


But this works and I have no idea why? Please help me.

myRef.addValueEventListener(new {
public void onDataChange( dataSnapshot) {
for ( item: dataSnapshot.getChildren()) {

Answer Source

The error is, that you have to use a But I think you have an import for com.firebase.client.ValueEventListener in your imports on top of the file.

Because of this, the compiler tries to use com.firebase.client.ValueEventListener as default, which obviously fails.

To fix this, look through your imports and remove the entry for com.firebase.client.ValueEventListener. Then you can add

This approach doesn't work if you have to use both of them. Then there's no other solution than using the full names (e.g. instead of just ValueEventListener) for both or at least one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download