Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

build-a-selfdestructing-message-android-app: Error Messages and Dialogs

I am not sure how to fix this error. I am using parser 1.4.1 jar file. Help me fix this issue.

02-26 14:00:26.288: V/Provider/Settings(19215): from settings cache , name = sound_effects_enabled , value = 0 02-26 14:00:26.288: D/AndroidRuntime(19215): Shutting down VM 02-26 14:00:26.289: W/dalvikvm(19215): threadid=1: thread exiting with uncaught exception (group=0x414589a8) 02-26 14:00:26.295: E/AndroidRuntime(19215): FATAL EXCEPTION: main 02-26 14:00:26.295: E/AndroidRuntime(19215): java.lang.NullPointerException 02-26 14:00:26.295: E/AndroidRuntime(19215): at com.turtalabs.bagit.SignUpActivity$1.onClick(SignUpActivity.java:32) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.view.View.performClick(View.java:4243) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.view.View$PerformClick.run(View.java:17520) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.os.Handler.handleCallback(Handler.java:725) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.os.Handler.dispatchMessage(Handler.java:92) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.os.Looper.loop(Looper.java:153) 02-26 14:00:26.295: E/AndroidRuntime(19215): at android.app.ActivityThread.main(ActivityThread.java:5297) 02-26 14:00:26.295: E/AndroidRuntime(19215): at java.lang.reflect.Method.invokeNative(Native Method) 02-26 14:00:26.295: E/AndroidRuntime(19215): at java.lang.reflect.Method.invoke(Method.java:511) 02-26 14:00:26.295: E/AndroidRuntime(19215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 02-26 14:00:26.295: E/AndroidRuntime(19215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 02-26 14:00:26.295: E/AndroidRuntime(19215): at dalvik.system.NativeStart.main(Native Method)

Code for SignUpActivity.class and activity_sign_up.xml file SignUpActivity.class

import android.app.Activity; import android.app.AlertDialog; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText;

public class SignUpActivity extends Activity {

protected EditText mUsername;
protected EditText mPassword;
protected EditText mEmail;
protected Button mSignUpButton;


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

    mUsername = (EditText)findViewById(R.id.usenameField);
    mPassword = (EditText)findViewById(R.id.passwordField);
    mEmail = (EditText)findViewById(R.id.emailField);
    mSignUpButton = (Button)findViewById(R.id.signupButton);



    mSignUpButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String username = mUsername.getText().toString();
            String password = mPassword.getText().toString();
            String email = mEmail.getText().toString();

            username = username.trim();
            password = password.trim();
            email = email.trim();

            if (username.isEmpty() || password.isEmpty() || email.isEmpty()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
                builder.setMessage(R.string.sign_up_error_message)
                    .setTitle(R.string.sign_up_error_title)
                    .setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
            }
            else {
                // create the new user!
            }
        }
    });
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.sign_up, menu);
    return true;
}

}

** activity_sign_up.xml**

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".SignUpActivity" >

<EditText
    android:id="@+id/usernameField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:ems="10"
    android:hint="@string/username_hint" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/passwordField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/usernameField"
    android:layout_below="@+id/usernameField"
    android:ems="10"
    android:inputType="textPassword"
    android:hint="@string/password_hint" />

<EditText
    android:id="@+id/emailField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/passwordField"
    android:layout_below="@+id/passwordField"
    android:ems="10"
    android:inputType="textEmailAddress"
    android:hint="@string/email_hint" />

<Button
    android:id="@+id/signupButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/emailField"
    android:layout_below="@+id/emailField"
    android:text="@string/sign_up_button_label" />

</RelativeLayout>

1 Answer

This ## mUsername = (EditText)findViewById(R.id.usenameField); Should be ## mUsername = (EditText)findViewById(R.id.usernameField); I am not able to update my R.java file. It still have usenameField and usernameField string.