0
  1. I need to retrieved data from database Firebase. But I have problem since when I try to retrieve the data, the application will stop.

  2. this is the code for retrievedPoint.java

    final FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference ref = database.getReference("reloadPoint");
    
    ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ReloadPoint rp = dataSnapshot.getValue(ReloadPoint.class);
            System.out.println(rp);
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
            System.out.println("The read failed: " + databaseError.getCode());
        }
    });
    
    ref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            ReloadPoint newPost = dataSnapshot.getValue(ReloadPoint.class);
            System.out.println("Email: " + newPost.getmEmail());
            System.out.println("Point: " + newPost.getmPoint());
            System.out.println("User id: " + newPost.getmUserid());
        }
    
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
    
        }
    
        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
    
        }
    
        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
    
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
    
        }
    });
    
  3. this the code for the ReloadPoint class.

    public class ReloadPoint {
    
    private String mEmail;
    private String mPoint;
    private String mUserid;
    
    public ReloadPoint(String email, String point, String userid) {
       this.mEmail = email;
       this.mPoint = point;
       this.mUserid = userid;
    
    }
    
    public String getmEmail() {
     return mEmail;
    }
    
    public void setmEmail(String mEmail) {
        this.mEmail = mEmail;
    }
    
    public String getmPoint() {
      return mPoint;
    }
    
    public void setmPoint(String mPoint) {
      this.mPoint = mPoint;
    }
    
    public String getmUserid() {
        return mUserid;
    }
    
    public void setmUserid(String mUserid) {
       this.mUserid = mUserid;
    }
    }
    
  4. This is the thing that I want to retrieve from Firebase. this is the child that I want to retrieve

  5. This is the Android where the retrived data will appear if the retrieved process is success.retrievedPoint.xml

  6. Result from log cat.Log cat result

Please help me.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Possible duplicate of [users does not define no argument constructor](https://stackoverflow.com/questions/47706601/users-does-not-define-no-argument-constructor) – orimdominic Jul 16 '18 at 09:48
  • Possible duplicate of [Error in fetching data from firebase to recycler view](https://stackoverflow.com/questions/51035276/error-in-fetching-data-from-firebase-to-recycler-view) – Alex Mamo Jul 16 '18 at 09:51

3 Answers3

2

As the error message implies, your ReloadPoint class needs a no-args constructor, e.g :

public ReloadPoint() {

}
Arnaud
  • 17,229
  • 3
  • 31
  • 44
2

Please include a no-argument constructor in your ReloadPoint class like so

public ReloadPoint() {

}

see this question users does not define no argument constructor

orimdominic
  • 995
  • 10
  • 23
1
public class ReloadPoint {

private String mEmail;
private String mPoint;
private String mUserid;

//Ni hang lupa ni. apa la sakinah
//Klau da soklan lagi, hbungi kt insta id: nyrtron
public ReloadPoint(){

}

public ReloadPoint(String email, String point, String userid) {
   this.mEmail = email;
   this.mPoint = point;
   this.mUserid = userid;

}

public String getmEmail() {
 return mEmail;
}

public void setmEmail(String mEmail) {
    this.mEmail = mEmail;
}

public String getmPoint() {
  return mPoint;
}

public void setmPoint(String mPoint) {
  this.mPoint = mPoint;
}

public String getmUserid() {
    return mUserid;
}

public void setmUserid(String mUserid) {
   this.mUserid = mUserid;
}
}

I think I have found your problem.

DatabaseReference ref = database.getReference().child("reloadPoint").child("Waniyanazahri");

UPDATED ANSWER: Its look like you haven't call the class.

ref.addValueEventListener(new ValueEventListener() {
   @Override
   public void onDataChange(DataSnapshot dataSnapshot) {
      //Add this one
      ReloadPoint rp = new ReloadPoint();
      rp = dataSnapshot.getValue(ReloadPoint.class);
      System.out.println(rp);
    }
   @Override
   public void onCancelled(DatabaseError databaseError) {
   System.out.println("The read failed: " + databaseError.getCode());
   }
});
Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46