'setValue' Android Studio shows error

Issue

we are trying to connect Firebase to Android Studio. The first two steps are marked with a green tick, but for some reason when we try to set the value of myRef, Android Studio says ‘Cannot resolve symbol 'setValue'. 'setValue' is coloured red.

Screenshot of code:

enter image description here

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");

myRef.setValue("Hello, World!");

Solution

The statement myRef.setValue("Hello, World!"); is misplaced. It must be inside a method body. Move it inside the onCreate() or onStart() method.

Answered By – Bob Snyder

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published