I need a function that checks if a value exists or not in my firebase realtime database. I tried to write the code below:
public boolean esiste(String desc, DatabaseReference meseref){
boolean exists = false;
meseref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.child(desc).exists()){
exists = true;
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
return exists;
}
Maybe it is not the best way, but it is seems very simple for me (I am not an expert programmer). The problem is that compiler says that "Variable 'exists' is accessed from within inner class, needs to be final or effectively final", and I have an error.
So, how can I make a function that checks if the value exists or not?
Thank you so much