am trying to build a basic android application with registration form appears once the application is running, it crashes when i run on the emulator this is my code
onCreate code inside main
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
tv3 = (TextView) findViewById(R.id.textView3);
et1 = (EditText) findViewById(R.id.email);
et2 = (EditText) findViewById(R.id.name);
et3 = (EditText) findViewById(R.id.password);
submit = (Button) findViewById(R.id.register);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = et1.getText().toString();
String name = et2.getText().toString();
String password = et3.getText().toString();
//Some code running
}
});
this is the console log
and here is showing that the problem is with the onClockListenr am trying to call
02-05 18:11:46.275 2121-2121/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mazinalmaskari.twitter, PID: 2121
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.mazinalmaskari.twitter/com.example.mazinalmaskari.twitter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
Button attribute inside signup.xml file
<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="30dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/password"
android:text="Register"
android:textSize="15dp"
android:textColor="@android:color/white"/>
why is the app crashing -_-