Arduino Arduino - 3 months ago 27
Android Question

Firebase can't retrieve data

Model Class:

public class Points {

public String score;

public Points(){


public Points(String score) {
this.score = score;

public String getScore() {
return score;

public void setScore(String score) {
this.score = score;

Code for updating:

private void updateUser(String name) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (!name.equals("")) {
Toast.makeText(this, "update Done", Toast.LENGTH_SHORT).show();

Code for retrieving:

private void addUserChangeListener() {
final FirebaseUser getData = firebaseAuth.getCurrentUser();
// User data change listener
dbRefer.child("User").child(getData.getUid()).child("score").addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
Points user = dataSnapshot.getValue(Points.class);

Toast.makeText(GameActivity.this, "Retrieved Data is: " + getData, Toast.LENGTH_SHORT).show();

// Check for null
if (user == null) {
Log.e(TAG, "User data is null!");

Log.e(TAG, "User data is changed!" + user.getScore());

// Display newly updated name and email

// clear edit text


public void onCancelled(DatabaseError databaseError) {
Toast.makeText(GameActivity.this, "Can't Get data", Toast.LENGTH_SHORT).show();

Code for updating is working, what I am facing now is the retrieving part, I can't seem to get the data out from my database. Help and guidance is needed thanks.


Normally I'd pull information just as you are, as objects, but because your only pulling one piece of information, instead of creating a points object and all of that I would just pull it manually and put it.

     dbRefer.child("User").child(getData.getUid()).addValueEventListener(new ValueEventListener() {
    public void onDataChange(DataSnapshot dataSnapshot) { 
String name = (String) dataSnapshot.child("score").getValue();