'Unable to retrievw data of firebase current online user

I want to retrieve data of specific node (clicksRemain) of current online user from firebase into a textView but the data is not showing. Below is my code.

PracticeActivity


public class PracticeActivity extends AppCompatActivity {

    TextView link1;
    DatabaseReference dRef;
    FirebaseDatabase firebaseDatabase;
   


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_practice);

        link1 = findViewById(R.id.link1);
        
        firebaseDatabase = FirebaseDatabase.getInstance();
        dRef = FirebaseDatabase.getInstance().getReference();

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        if (user != null) {
            dRef.child("clicksRemain").addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    String remainingClicks = snapshot.getValue(String.class);
                    link1.setText(remainingClicks);
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {

                }
            });
        }else{
            link1.setText("10");
        }
    }
    }

I think the code is correct to check if a user is logged in or not as if a user is logout then the app shows the value 10 as written in this code.

Snapshot of database

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source