title: Firebase retriving single text data and setting it in a textview
body: <p>I have been trying to retrieve only the username data saved in firebase and have it displayed in a text view on navigation drawer but I either keep getting errors and app crashes or nothing gets displayed in the text view and app doesn't crash. app doesn't crash with this code.</p>
  
  <p><img src="https://i.stack.imgur.com/yWUnt.jpg" alt="app"></p>
  
  <p>This is my database</p>
  
  <p><img src="https://i.stack.imgur.com/FhBaf.png" alt="This is my database"></p>
  
  <p>Data Model</p>
  
  <pre><code>public class users {
      private String userID;
      private String userEmail;
      private String userName;
      private String userUsername;
  
  
      public users() {
  
      }
  
      public users(String userID, String userEmail, String userName, String userUsername) {
          this.userID = userID;
          this.userEmail = userEmail;
          this.userName = userName;
          this.userUsername = userUsername;
      }
  
      public String getUserID() {
          return userID;
      }
  
      public String getUserEmail() {
          return userEmail;
      }
  
      public String getUserName() {
          return userName;
      }
  
      public String getUserUsername() {
          return userUsername;
      }
  
      public void setUserID(String userID) {
          this.userID = userID;
      }
  
      public void setUserEmail(String userEmail) {
          this.userEmail = userEmail;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public void setUserUsername(String userUsername) {
          this.userUsername = userUsername;
      }
  }
  </code></pre>
  
  <p>Main Activity</p>
  
  <pre><code>//ASSIGNING FIREBASE OBJECTS.
  mAuth = FirebaseAuth.getInstance();
  mFire = FirebaseDatabase.getInstance();
  user = mAuth.getCurrentUser();
  userID = user.getUid();
  
  mDatabase = mFire.getReference("users");
  usernameRef = mDatabase.child(userID);
  
  
  //METHODS
  checkIfUserSignedIN();
  InitImgLoader();
  setProfileImg();
  
  
  
  //NAVIGATION LAYOUT.
  NavigationView navigationView = findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  
  
  
  //HEADER VIEW LAYOUT.
  username = findViewById(R.id.Username_onDrawer);
  View headView = navigationView.getHeaderView(0);
  ImageView pp = headView.findViewById(R.id.profile_image);
  pp.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
  
          Intent i = new Intent(MainActivity.this, ProfileActivity.class);
          startActivity(i);
      }
  });
  
  usernameRef.addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
  
  
         for (DataSnapshot ds : dataSnapshot.child("userUsername").getChildren()){
              users usernamE = new users();
              usernamE.setUserUsername(ds.child(userID).getValue(users.class).getUserUsername());
  
  
              username.setText(usernamE.getUserUsername());
          }
  
      }
  
      @Override
      public void onCancelled(DatabaseError databaseError) {
  
      }
  });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yWUnt.jpg" rel="nofollow noreferrer">I'm trying to set username below this image view</a></p>
  
  <p>**UPDATE!***strong text*****
  It only seems to work if I have the database like this with the following code..</p>
  
  <pre><code> mDatabase.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
  
  
                  String UserUserName = String.valueOf(dataSnapshot.child("userUsername").getValue());
  
  
                  username.setText(UserUserName);
  
              }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7Uk1L.png" rel="nofollow noreferrer">database with No user id </a></p>
  
  <p>This is how i saved the data to firebase</p>
  
  <pre><code> //USER SIGNUP INFORMATION METHOD.
  private void push(){
  
      String Email = email.getText().toString().trim();
      String Name = name.getText().toString().trim();
      String Username = userName.getText().toString().trim();
  
      String id = mDatabase.push().getKey();
  
      users Users = new users(id, Email, Name, Username);
  
      mDatabase.child(id).setValue(Users);
  </code></pre>