title: How to get object value from firebase inner class ValueEventListner in android
body: <p>How do I put the username value into MyName value so that I can get real time value because whenever I try to use it it shows Null pointer exception.</p>
  
  <pre><code>String username;
  
  ref.addValueEventListener(new ValueEventListener() {
  
  
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
    String userinfo = dataSnapshot.getValue(User.class);
       username = userInfo.username;
  }
  
  @Override
  public void onCancelled(FirebaseError firebaseError) {
  
  }
  });
  
  String MyName = username;
  </code></pre>