title: Firebase Null object Reference
body: <p>When running updateList(), it works as it loads up the already-entered data from Firebase. This is a chat app so when someone types a message, Firebase updates in real time, which works as well. </p>
  
  <p>The problem is I get a NullPointerException (Which shouldn't be the case) where I create a new Message object (Message mess = new Mess....). Why am I receiving this error and why is everything I tried not working?</p>
  
  <p>Error = java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference.</p>
  
  <p>I tried a lock, a boolean, and tried making the variables global variables.  </p>
  
  <pre><code>public void sendButtonClicked(View view) {
  
      final String messageValue = userMessage.getText().toString().trim();
      final String date = "4:20";
      final String userName = "Rob";
          if (!TextUtils.isEmpty(messageValue)) {
              final DatabaseReference newPost = reference.push();
              newPost.child("Content").setValue(messageValue);
              newPost.child("Date").setValue(date);
              newPost.child("userName").setValue(userName);
          }
      }
  
  private void updateList() {
      reference.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              Message mess = new Message(dataSnapshot.child("Content").getValue().toString(), dataSnapshot.child("Date").getValue().toString(),dataSnapshot.child("userName").getValue().toString());
              result.add(mess);
              adapter.notifyDataSetChanged();
          }
  
          @Override
          public void onChildChanged(DataSnapshot dataSnapshot, String s) {
              Message message = dataSnapshot.getValue(Message.class);
  
              int index = getItemIndex(message);
  
              result.set(index, message);
              adapter.notifyItemChanged(index);
          }
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
              Message message = dataSnapshot.getValue(Message.class);
  
              int index = getItemIndex(message);
  
              result.remove(index);
              adapter.notifyItemRemoved(index);
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  }
  </code></pre>
  
  <p>Snapshot of how the data looks in Firebase</p>
  
  <p><a href="https://i.stack.imgur.com/oU9dJ.png" rel="nofollow noreferrer">FireBase Screesnhot</a></p>