title: Android Studio Attempt to invoke virtual method on a null object reference error
body: <p>I have problem with LoginNew activity. When I click "Zaloguj się" button (id LogIn) app stops working. 
  <code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference</code> error is displaying. </p>
  
  <p>Error:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.zapp4, PID: 23951
      java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
          at com.example.zapp4.LoginNew.userLogin(LoginNew.java:61)
          at com.example.zapp4.LoginNew.onClick(LoginNew.java:120)
          at android.view.View.performClick(View.java:6294)
          at android.view.View$PerformClick.run(View.java:24770)
          at android.os.Handler.handleCallback(Handler.java:790)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6494)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  Process 23951 terminated.
  </code></pre>
  
  <p>LoginNew.java code:</p>
  
  <pre><code>package com.example.zapp4;
  import android.content.Intent;
  
  
  import android.os.Bundle;
  import android.util.Patterns;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.cardview.widget.CardView;
  
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.AuthResult;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.auth.FirebaseAuthUserCollisionException;
  
  public class LoginNew extends AppCompatActivity implements View.OnClickListener {
  
      FirebaseAuth mAuth;
      EditText EditTextUsername;
      EditText EditTextPassword;
      ProgressBar progressBar;
      Button Przyciskzaloguj;
      ImageView zcoinimage;
      TextView zcoinnumber;
      CardView LogIn;
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login_new);
  
          mAuth = FirebaseAuth.getInstance();
          EditTextUsername = (EditText) findViewById(R.id.EditTextUsernameedit);
          EditTextPassword = (EditText) findViewById(R.id.EditTextPasswordedit);
          Przyciskzaloguj = (Button) findViewById(R.id.Przyciskzaloguj);
          zcoinnumber = (TextView) findViewById(R.id.zcoinnumber);
          zcoinimage = (ImageView) findViewById(R.id.zcoinimage);
  
          progressBar = findViewById(R.id.progressBar);
  
          LogIn = findViewById(R.id.LogIn);
  
  
          findViewById(R.id.LogIn).setOnClickListener(this);
  
      }
  
      private void userLogin() {
  
          String username = EditTextUsername.getText().toString();
          String password = EditTextPassword.getText().toString().trim();
  
  
          if (username.isEmpty()) {
              EditTextUsername.setError("Email jest wymagany");
              EditTextUsername.requestFocus();
              return;
          }
          if (password.isEmpty()) {
              EditTextPassword.setError("Hasło jest wymagane");
              EditTextPassword.requestFocus();
              return;
          }
  
          if (password.length() &lt; 6) {
              EditTextPassword.setError("Minimalna długość hasła wynosi 6");
              EditTextPassword.requestFocus();
              return;
          }
  
          if (!Patterns.EMAIL_ADDRESS.matcher(username).matches()) {
              EditTextUsername.setError("Wprowadź poprawny email");
              EditTextUsername.requestFocus();
              return;
          }
          progressBar.setVisibility(View.VISIBLE);
          mAuth.signInWithEmailAndPassword(username, password).addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  progressBar.setVisibility(View.GONE);
                  if (task.isSuccessful()) {
                      finish();
                      Intent intent = new Intent(LoginNew.this, HomeActivity.class);
                      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      Przyciskzaloguj.setVisibility(View.GONE);
                      zcoinnumber.setVisibility(View.VISIBLE);
                      zcoinimage.setVisibility(View.VISIBLE);
                      startActivity(intent);
                  } else {
                      Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                  }
              }
          });
      }
  
      @Override
      protected void onStart() {
          super.onStart();
  
          if (mAuth.getCurrentUser() != null) {
              finish();
              startActivity(new Intent(this, HomeActivity.class));
          }
      }
  
      @Override
      public void onClick(View view) {
          if (view.getId() == R.id.LogIn) {
              userLogin();
          }
      }
  
  }
  </code></pre>
  
  <p>activity_login_new.xml code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/gradient"
      tools:context=".LoginNew"&gt;
  
  
      &lt;ImageView
          android:id="@+id/imageView"
          android:layout_width="233dp"
          android:layout_height="297dp"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:layout_alignParentEnd="true"
          android:layout_alignParentBottom="true"
          android:layout_marginStart="88dp"
          android:layout_marginTop="47dp"
          android:layout_marginEnd="88dp"
          android:layout_marginBottom="387dp"
          android:contentDescription="@string/todo"
          app:srcCompat="@drawable/znaczek_druzyny" /&gt;
  
      &lt;androidx.appcompat.widget.AppCompatEditText
          android:id="@+id/EditTextUsernameedit"
          android:layout_width="250dp"
          android:layout_height="40dp"
          android:background="#11000000"
          android:hint="@string/prompt_email"
          android:inputType="textPersonName"
          android:textSize="16sp"
          android:layout_marginBottom="35dp"
          android:layout_above="@+id/EditTextPasswordedit"
          android:layout_centerHorizontal="true"
          android:autofillHints="" /&gt;
  
      &lt;androidx.appcompat.widget.AppCompatEditText
          android:id="@+id/EditTextPasswordedit"
          android:layout_width="250dp"
          android:layout_height="40dp"
          android:layout_alignStart="@+id/EditTextUsernameedit"
          android:layout_alignParentBottom="true"
          android:layout_marginStart="2dp"
          android:layout_marginBottom="201dp"
          android:background="#11000000"
          android:textSize="16sp"
          android:hint="@string/prompt_password"
          android:inputType="textPassword"
          android:autofillHints="" /&gt;
  
  
      &lt;androidx.cardview.widget.CardView
          android:id="@+id/LogIn"
          android:layout_width="300dp"
          android:layout_height="50dp"
          android:layout_alignParentStart="true"
          android:layout_alignParentEnd="true"
          android:layout_alignParentBottom="true"
          android:layout_marginStart="55dp"
          android:layout_marginEnd="55dp"
          android:layout_marginBottom="85dp"
          app:cardBackgroundColor="@color/colorAccent"
          app:cardCornerRadius="25dp"
          app:cardElevation="10dp"&gt;
  
          &lt;TextView
              android:id="@+id/textView"
              android:layout_width="wrap_content"
              android:layout_height="50dp"
  
              android:layout_gravity="center"
              android:layout_marginTop="13dp"
              android:layout_marginBottom="13dp"
              android:text="@string/action_sign_in"
              android:textColor="#fff"
              android:textSize="30sp" /&gt;
      &lt;/androidx.cardview.widget.CardView&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressBar"
          style="?android:attr/progressBarStyle"
          android:layout_width="265dp"
          android:layout_height="265dp"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:layout_alignParentEnd="true"
          android:layout_alignParentBottom="true"
          android:layout_marginStart="65dp"
          android:layout_marginTop="230dp"
          android:layout_marginEnd="65dp"
          android:layout_marginBottom="230dp"
          android:visibility="gone" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>