title: Error writing to firebase. App keeps crashing
body: <p>So, I am new to android and firebase. I am trying to create a messaging app. But as soon as I click the send button my app crashes. I know exactly where the app is crashing. It is crashing right after I click the send button where I am trying to put data on the database. Checked Logcat and everything still can't figure out how to fix it. Heres the code of MainActivity.java</p>
  
  <p>import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;</p>
  
  <p>public class MainActivity extends AppCompatActivity {</p>
  
  <pre><code>private Button sendButton;
  private TextView editMessage;
  private ListView messageList;
  
  private FirebaseDatabase firebaseDatabase;
  private DatabaseReference qDatabaseReference;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      try {
          firebaseDatabase = FirebaseDatabase.getInstance();
          qDatabaseReference = qDatabaseReference.getRef().child("messages");
      }catch(Exception e){
          Toast.makeText(this,"Database Error!", Toast.LENGTH_SHORT);
          e.printStackTrace();
      }
  
      sendButton = findViewById(R.id.sendButton);
      editMessage = findViewById(R.id.messageEdit);
      messageList = findViewById(R.id.messageList);
  
      sendButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Message message = new Message("user","TEST");
              //app crashes here at the line below
              qDatabaseReference.push().setValue(message);
              editMessage.setText("");
          }
      });
  }
  }
  </code></pre>
  
  <p>Code of my Message class</p>
  
  <pre><code>public class Message {
  
  private int maxLength = 1000;
  
  private String name;
  private String text;
  
  Message(){
      name = null;
      text = null;
  }
  
  Message(String name, String message){
      this.name = name;
      this.text = message;
  }
  }
  </code></pre>
  
  <p>Finally found the error in LogCat</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.DatabaseReference.push()' on a null object reference
      at com.codeswingstudios.codewise.MainActivity$1.onClick(MainActivity.java:42)
      at android.view.View.performClick(View.java:5293)
      at android.view.View$PerformClick.run(View.java:21660)
      at android.os.Handler.handleCallback(Handler.java:815)
      at android.os.Handler.dispatchMessage(Handler.java:104)
      at android.os.Looper.loop(Looper.java:227)
      at android.app.ActivityThread.main(ActivityThread.java:6100)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  </code></pre>