title: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
body: <p>All I want to do is start a new intent on click of a button. Here is my code(I have removed irrelevant parts):</p>
  
  <p><code>activity_login.xml</code>:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_horizontal"
      tools:context="com.example.android.altro.LoginActivity"&gt;
  
      &lt;!-- Login progress --&gt;
      &lt;ProgressBar
          android:id="@+id/login_progress"
          style="?android:attr/progressBarStyleLarge"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginBottom="8dp"
          android:visibility="gone" /&gt;
  
      &lt;ScrollView
          android:id="@+id/login_form"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;LinearLayout
              android:id="@+id/email_login_form"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"&gt;
  
              &lt;android.support.design.widget.TextInputLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"&gt;
  
                  &lt;AutoCompleteTextView
                      android:id="@+id/email"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:hint="@string/prompt_email"
                      android:inputType="textEmailAddress"
                      android:maxLines="1"
                      android:textColor="@color/colorWhite"
                      android:singleLine="true" /&gt;
  
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
              &lt;android.support.design.widget.TextInputLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"&gt;
  
                  &lt;EditText
                      android:id="@+id/password"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:hint="@string/prompt_password"
                      android:imeActionId="@+id/login"
                      android:imeActionLabel="@string/action_sign_in_short"
                      android:imeOptions="actionUnspecified"
                      android:inputType="textPassword"
                      android:maxLines="1"
                      android:singleLine="true" /&gt;
  
              &lt;/android.support.design.widget.TextInputLayout&gt;
  
              &lt;Button
                  android:id="@+id/email_sign_up_button"
                  style="?android:textAppearanceMedium"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:background="@drawable/rounded_button"
                  android:onClick="registerNewUser"
                  android:text="@string/action_sign_up"
                  android:textAllCaps="false" /&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>On clicking <code>@+id/email_sign_up_button</code> <code>registerNewUser</code> is called. I have defined this fuction in <code>LoginActivity.java</code>:</p>
  
  <pre><code>public class LoginActivity extends AppCompatActivity implements LoaderCallbacks&lt;Cursor&gt; {
  
      /**
       * Id to identity READ_CONTACTS permission request.
       */
      private static final int REQUEST_READ_CONTACTS = 0;
  
      /**
       * A dummy authentication store containing known user names and passwords.
       * TODO: remove after connecting to a real authentication system.
       */
      private static final String[] DUMMY_CREDENTIALS = new String[]{
              "foo@example.com:hello", "bar@example.com:world"
      };
      /**
       * Keep track of the login task to ensure we can cancel it if requested.
       */
      private UserLoginTask mAuthTask = null;
  
      // UI references.
      private AutoCompleteTextView mEmailView;
      private EditText mPasswordView;
      private View mProgressView;
      private View mLoginFormView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          // Set up the login form.
          mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
          populateAutoComplete();
  
          mPasswordView = (EditText) findViewById(R.id.password);
          mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
              @Override
              public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                  if (id == R.id.login || id == EditorInfo.IME_NULL) {
                      attemptLogin();
                      return true;
                  }
                  return false;
              }
          });
  
          Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
          mEmailSignInButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {
                  attemptLogin();
              }
          });
  
          mLoginFormView = findViewById(R.id.login_form);
          mProgressView = findViewById(R.id.login_progress);
  
         /* Button mRegisterButton = (Button) findViewById(R.id.email_sign_up_button);
          mRegisterButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(view.getContext(), RegisterActivity.class);
                  startActivity(intent);
              }
          });*/
      }
  
      public void registerNewUser(View view) {
          Intent intent = new Intent(this, RegisterActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>I also tried doing it by finding view and then creating an intent (the code is commented out in <code>onCreate()</code> method. That also gave me the same error:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.altro/com.example.android.altro.RegisterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
  </code></pre>