Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'setValue' Android Studio shows error

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!");
like image 501
M Y Avatar asked Nov 07 '25 07:11

M Y


1 Answers

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

like image 57
Bob Snyder Avatar answered Nov 11 '25 08:11

Bob Snyder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!