title: Retrieving data using Map from Firebase Database
body: <p>I am trying to retrieve data from firebase database in Map format but I am getting a null pointer exception.I have successfully inserted data using map into my firebase database.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class Chat extends AppCompatActivity {
  
    DatabaseReference databaseReference1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_chat);
  
      Firebase.setAndroidContext(this);
      databaseReference1 = FirebaseDatabase.getInstance().getReferenceFromUrl("URL");
  
      databaseReference1.addChildEventListener(new com.google.firebase.database.ChildEventListener() {
          @Override
          public void onChildAdded(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
              Map map = (Map) dataSnapshot.getValue();
              String message = map.get("text").toString();   //ERROR GOES HERE!!
              String userName = map.get("Username").toString();
  
          }
  
          @Override
          public void onChildChanged(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onChildRemoved(com.google.firebase.database.DataSnapshot dataSnapshot) {
  
          }
  
          @Override
          public void onChildMoved(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  }
  
  
  }
  </code></pre>