61337

Firebase realtime databae not working, setValue

I made sample by tutorial 'https://firebase.google.com/docs/database/android/start/?hl=ko' for Firebase realtime database

But I cannot see any data after onDataChanged 'EventValueListner'

Can you explain why that is?

FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("message"); myRef.setValue("Hello, World!"); // Read from the database myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // This method is called once with the initial value and again // whenever data at this location is updated. String value = dataSnapshot.getValue(String.class); Log.d("TAG", "Value is: " + value); } @Override public void onCancelled(DatabaseError error) { // Failed to read value Log.w("TAG", "Failed to read value.", error.toException()); } });

It is my code.

What is my fault?

Answer1:

this example will insert new user data in firebase db.

FirebaseDatabase database; DatabaseReference usersTable; database = FirebaseDatabase.getInstance(); usersTable = database.getReference("Users"); /*we work here */ usersTable.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { progressDialog.dismiss(); if (dataSnapshot.child(phoneEditText.getText().toString()).exists()) { Toast.makeText(SignUp.this, "Number already register", Toast.LENGTH_SHORT).show(); }else{ Users users = new Users(nameEditText.getText().toString(),passwordEditTex.getText().toString(),phoneEditText.getText().toString()); usersTable.child(phoneEditText.getText().toString()).setValue(users); Toast.makeText(SignUp.this, "Signup Sucessfully", Toast.LENGTH_SHORT).show(); finish(); } } @Override public void onCancelled(DatabaseError databaseError) { } });

<img src=https://www.e-learn.cn/content/wangluowenzhang/"https://i.stack.imgur.com/OG2nV.png" alt="sample database">

hope this will help you

Recommend

  • Retrieving data from nested object Firebase using Android/Java?
  • Filling data to spinner from firebase database
  • Invalid Firebase Path error while fetching database
  • how to make sure Query is not empty
  • Firebase database to Spinner [code cleaning help]
  • Changing a button's border color at onClick
  • Firebase onDataChange method is not called even if the data is changed
  • How can i add a String with multiple data to String Array
  • Use Glide load into Imageview but delay
  • Android + Firebase: synchronous for into an asynchronous function
  • Firebase Datasnapshot for getChildrenCount sets to zero
  • Is there any chance DataSnapshot value is null?
  • Can't get the return value from a method that retrieves data from Firebase Realtime database to
  • How to check if sub child exists in Firebase Realtime Database?
  • Firebase retrieve highest 100 score
  • Where does the firebase listeners listen to RAM or disk?
  • Get Last Seen in chats application
  • How to apply multiple query in android firebase? [duplicate]
  • Recyclerview is not updated with new Data
  • JsonMappingException: No suitable constructor found
  • Android Firebase addListenerForSingleValueEvent not called
  • Android Firebase query data
  • android.app.PendingIntent cannot be accessed ouside the package
  • GridView breaks while scrolling
  • NHibernate Validation Localization with S#arp Architecture
  • how to do an event when i swipe from fragment to the other
  • Update CALayer sublayers immediately
  • JFileChooser in front of fullscreen Swing application
  • Nant, Vault & Windows Integrated Authentication
  • Javascript Callbacks with Object constructor
  • Return words with double consecutive letters
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • LevelDB C iterator
  • unknown Exception android
  • Can't mass-assign protected attributes when import data from csv file
  • failed to connect to specific WiFi in android programmatically