i'm making an app that has a sign in or log in button, the log in button works perfectly but the sign up button gives me a fatal error, making the AVD to stop running the app, this is the code of the sign up activity
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.signup_activity);
// Set up the signup form.
usernameView = (EditText) findViewById(R.id.username);
passwordView = (EditText) findViewById(R.id.password);
passwordAgainView = (EditText) findViewById(R.id.passwordAgain);
// Set up the submit button click handler
findViewById(R.id.action_button).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Validate the sign up data
boolean validationError = false;
StringBuilder validationErrorMessage =
new StringBuilder(getResources().getString(R.string.error_intro));
if (isEmpty(usernameView)) {
validationError = true;
validationErrorMessage.append(getResources().getString(R.string.error_blank_username));
}
if (isEmpty(passwordView)) {
if (validationError) {
validationErrorMessage.append(getResources().getString(R.string.error_join));
}
validationError = true;
validationErrorMessage.append(getResources().getString(R.string.error_blank_password));
}
if (!isMatching(passwordView, passwordAgainView)) {
if (validationError) {
validationErrorMessage.append(getResources().getString(R.string.error_join));
}
validationError = true;
validationErrorMessage.append(getResources().getString(
R.string.error_mismatched_passwords));
}
validationErrorMessage.append(getResources().getString(R.string.error_end));
// If there is a validation error, display the error
if (validationError) {
Toast.makeText(SignUpActivity.this, validationErrorMessage.toString(), Toast.LENGTH_LONG)
.show();
return;
}
// Set up a progress dialog
final ProgressDialog dlg = new ProgressDialog(SignUpActivity.this);
dlg.setTitle("Please wait.");
dlg.setMessage("Signing up. Please wait.");
dlg.show();
// Set up a new Parse user
ParseUser user = new ParseUser();
user.setUsername(usernameView.getText().toString());
user.setPassword(passwordView.getText().toString());
// Call the Parse signup method
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
dlg.dismiss();
if (e != null) {
// Show the error message
Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
// Start an intent for the dispatch activity
Intent intent = new Intent(SignUpActivity.this, DispatchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
});
}
});
}
private boolean isEmpty(EditText etText) {
if (etText.getText().toString().trim().length() > 0) {
return false;
} else {
return true;
}
}
private boolean isMatching(EditText etText1, EditText etText2) {
if (etText1.getText().toString().equals(etText2.getText().toString())) {
return true;
} else {
return false;
}
}
and here is the manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity android:name=".SignUpOrLogInActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity >
<activity android:name=".DispatchActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
</application>
here is the logCat
Process: com.sebasdeldihotmail.mediocre11, PID: 2020
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sebasdeldihotmail.mediocre11/com.sebasdeldihotmail.mediocre11.SignUpActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.sebasdeldihotmail.mediocre11.SignUpActivity.onCreate(SignUpActivity.java:35)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
here is the code of the class that has the button that calls the sign up activity
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.signinorsignup_activity);
// Log in button click handler
((Button) findViewById(R.id.login)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Starts an intent of the log in activity
startActivity(new Intent(SignUpOrLogInActivity.this, LoginActivity.class));
}
});
// Sign up button click handler
((Button) findViewById(R.id.signup)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Starts an intent for the sign up activity
startActivity(new Intent(SignUpOrLogInActivity.this, SignUpActivity.class));
}
});
}
}
and here is the layout of the sign up
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#67AAE4">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_username"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
<EditText
android:id="@+id/passwordAgain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password_again"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</LinearLayout>
and here is the layout where the sign up button appears
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#67AAE4">
<Button
android:id="@+id/signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"/>
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
Thank you very much for reading :) .