Home » Android » Retrieved Firebase data into the top 5 android studio-Exceptionshub

Retrieved Firebase data into the top 5 android studio-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment


I have retrieved data from the Firebase database in which i have presented it in a list view. Now i only want to display the first 5 scores and should start from the highest score to the least. I am struggling to code this in android studio.

private FirebaseAuth firebaseAuth;
private ListView listView;
DatabaseReference databaseReference;
private FirebaseDatabase firebaseDatabase;
List < ScoreProfile > scoreList;

protected void onStart() {
    databaseReference.addValueEventListener(new ValueEventListener() {
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            for (DataSnapshot scoreSnapshot: dataSnapshot.getChildren()) {

                ScoreProfile scoreProfile = scoreSnapshot.getValue(ScoreProfile.class);

            ScoreInfoAdapter scoreInfoAdapter = new ScoreInfoAdapter(RankT.this, scoreList);


        public void onCancelled(@NonNull DatabaseError databaseError) {


protected void onCreate(Bundle savedInstanceState) {
        Toolbar toolbar = findViewById(R.id.toolbarMain);
        toolbar.setTitle("GymTastic Rank Table");

        listView = findViewById(R.id.listview);

        firebaseDatabase = FirebaseDatabase.getInstance();

        databaseReference = firebaseDatabase.getReference("Bench");

        scoreList = new ArrayList < > ();

        firebaseAuth = FirebaseAuth.getInstance();

This is the code that i am using within my activity. If you require more information, please do ask.

How to&Answers: