Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener on a null object reference at SignUpActivity.onCreate : <p>I tried to click the signup button in the loginactivity but when click the button in the app, it will jump out and give an error like this, it's true that there are questions similar to the one I'm asking, but I really tried all the solutions you proposed but it does not work for me.</p>

<p>The error:</p>

<pre><code>&gt; E/AndroidRuntime: FATAL EXCEPTION: main
&gt;     Process: com.fivenine.shareit, PID: 17033
&gt;     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fivenine.shareit/com.fivenine.shareit.AccountActivity.SignUpActivity}:
&gt; java.lang.NullPointerException: Attempt to invoke virtual method 'void
&gt; android.widget.Button.setOnClickListener(android.view.View$OnClickListener)'
&gt; on a null object reference
&gt;         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
&gt;         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
&gt;         at android.app.ActivityThread.-wrap12(ActivityThread.java)
&gt;         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
&gt;         at android.os.Handler.dispatchMessage(Handler.java:102)
&gt;         at android.os.Looper.loop(Looper.java:165)
&gt;         at android.app.ActivityThread.main(ActivityThread.java:6375)
&gt;         at java.lang.reflect.Method.invoke(Native Method)
&gt;         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
&gt;         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
&gt;      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
&gt; android.widget.Button.setOnClickListener(android.view.View$OnClickListener)'
&gt; on a null object reference
&gt;         at com.fivenine.shareit.AccountActivity.SignUpActivity.onCreate(SignUpActivity.java:44)
&gt;         at android.app.Activity.performCreate(Activity.java:6845)
&gt;         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
&gt;         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
&gt;         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808) 
&gt;         at android.app.ActivityThread.-wrap12(ActivityThread.java) 
&gt;         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541) 
&gt;         at android.os.Handler.dispatchMessage(Handler.java:102) 
&gt;         at android.os.Looper.loop(Looper.java:165) 
&gt;         at android.app.ActivityThread.main(ActivityThread.java:6375) 
&gt;         at java.lang.reflect.Method.invoke(Native Method) 
&gt;         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 
&gt;         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
</code></pre>

<p>here is the SignUpActivity.java:</p>

<pre><code>import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.fivenine.shareit.MainActivity;
import com.fivenine.shareit.R;
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;

public class SignUpActivity extends AppCompatActivity {

    private EditText inputEmail, inputPassword;
    private Button btnSignIn, btnSignUp, btnResetPassword;
    private ProgressBar progressBar;
    private FirebaseAuth auth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);

        //Get Firebase auth instance

        auth = FirebaseAuth.getInstance();

        btnSignIn = (Button) findViewById(R.id.sign_in_button);
        btnSignUp = (Button) findViewById(R.id.sign_up_button);
        inputEmail = (EditText) findViewById(R.id.email);
        inputPassword = (EditText) findViewById(R.id.password);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        btnResetPassword = (Button) findViewById(R.id.btn_reset_password);

        btnResetPassword.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                startActivity(new Intent(SignUpActivity.this, ResetPasswordActivity.class));
            }
        });

        btnSignIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        btnSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String email = inputEmail.getText().toString().trim();
                String password = inputPassword.getText().toString().trim();

                if (TextUtils.isEmpty(email)){
                    Toast.makeText(getApplicationContext(), "Enter email address!",
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(password)){
                    Toast.makeText(getApplicationContext(), "Enter password!",
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if (password.length() &lt; 6){
                    Toast.makeText(getApplicationContext(), "Password too short,enter minimum 6 characters!",
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                progressBar.setVisibility(View.VISIBLE);
                //create user
                auth.createUserWithEmailAndPassword(email, password)
                        .addOnCompleteListener(SignUpActivity.this, new OnCompleteListener&lt;AuthResult&gt;() {
                            @Override
                            public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                                Toast.makeText(SignUpActivity.this,"createUserWithEmail:onComplete:" + task.isSuccessful(),
                                        Toast.LENGTH_SHORT).show();
                                progressBar.setVisibility(View.GONE);

                                if(!task.isSuccessful()){
                                    Toast.makeText(SignUpActivity.this, "Authenticaton faled." + task.getException(),
                                            Toast.LENGTH_SHORT).show();
                                }else{
                                    startActivity(new Intent(SignUpActivity.this,
                                            MainActivity.class));
                                    finish();
                                }
                            }
                        });
            }
        });
    }

    @Override
    protected void onResume(){
        super.onResume();
        progressBar.setVisibility(View.GONE);
    }
}
</code></pre>

<p>The activity_sign_up.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.constraint.ConstraintLayout 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"
    tools:context="com.fivenine.shareit.AccountActivity.SignUpActivity"&gt;


    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/gradient_6"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="@dimen/activity_horizontal_margin"&gt;

        &lt;ImageView
            android:layout_width="75dp"
            android:layout_height="80dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="30dp"
            android:contentDescription=""
            android:src="@drawable/profile"
            tools:ignore="ContentDescription" /&gt;

        &lt;EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:textColor="@android:color/black"/&gt;

        &lt;EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true"
            android:hint="@string/hint_password"
            android:imeActionId="@integer/login"
            android:imeOptions="actionUnspecified"
            android:inputType="textPassword"
            android:maxLines="1"
            android:textColor="@android:color/black"/&gt;
        &lt;Button
            android:id="@+id/sign_up_button"
            style="?android:textAppearanceSmall"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:background="@drawable/btn_corner_pink_gradient"
            android:text="@string/action_sign_in_short"
            android:textColor="@android:color/white"
            android:textStyle="bold"/&gt;

       &lt;!-- &lt;Button
            android:id="@+id/btn_reset_password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:background="@null"
            android:text="@string/btn_forgot_password"
            android:textAllCaps="false"
            android:textColor="@color/colorAccent"/&gt; --&gt;

        &lt;!-- Link to login screen --&gt;

        &lt;Button
            android:id="@+id/sign_in_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:background="@null"
            android:text="@string/btn_link_to_login"
            android:textAllCaps="false"
            android:textColor="@color/colorWhite"
            android:textSize="15sp"/&gt;

    &lt;/LinearLayout&gt;

    &lt;ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="20dp"
        android:visibility="gone"/&gt;


&lt;/android.support.constraint.ConstraintLayout&gt;
</code></pre>
