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 Self-Destructing Message Android App Starting the App Adding the Sign Up Screen

Run time error =[

I did everything exactly the same but still got a run time error. Anyone experience the same problem?

6 Answers

Paul Stevens
Paul Stevens
4,125 Points

Hello,

Can you give us some more information please? Can you show us your code, and the errors you are getting? We will help.

Paul :)

Oh, sorry for the lack of the information. Give me some time, I will organize the information and post it here. (I wish I can upload images here...)

The following are the errors from the log cat (sorry I just copy and paste it here).

04-12 17:43:13.107: E/AndroidRuntime(3711): FATAL EXCEPTION: main 04-12 17:43:13.107: E/AndroidRuntime(3711): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ribbit/com.example.ribbit.LoginActivity}: java.lang.NullPointerException 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.os.Handler.dispatchMessage(Handler.java:99) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.os.Looper.loop(Looper.java:130) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-12 17:43:13.107: E/AndroidRuntime(3711): at java.lang.reflect.Method.invokeNative(Native Method) 04-12 17:43:13.107: E/AndroidRuntime(3711): at java.lang.reflect.Method.invoke(Method.java:507) 04-12 17:43:13.107: E/AndroidRuntime(3711): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-12 17:43:13.107: E/AndroidRuntime(3711): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-12 17:43:13.107: E/AndroidRuntime(3711): at dalvik.system.NativeStart.main(Native Method) 04-12 17:43:13.107: E/AndroidRuntime(3711): Caused by: java.lang.NullPointerException 04-12 17:43:13.107: E/AndroidRuntime(3711): at com.example.ribbit.LoginActivity.onCreate(LoginActivity.java:28) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-12 17:43:13.107: E/AndroidRuntime(3711): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 04-12 17:43:13.107: E/AndroidRuntime(3711): ... 11 more

Paul Stevens
Paul Stevens
4,125 Points

Here is the problem Line:

Caused by: java.lang.NullPointerException 04-12 17:43:13.107: E/AndroidRuntime(3711): at com.example.ribbit.LoginActivity.onCreate(LoginActivity.java:28)

Can you paste in your LoginActivity Code, and if possible highlight line 28.

Paul :)

You can upload images to imgur.com for free and then paste the link here if you want.

Here are the codes.

public class LoginActivity extends ActionBarActivity {

protected TextView mSignUpTextView;

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

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();

    mSignUpTextView = (TextView)findViewById(R.id.signUpText);

            //Line 28
    mSignUpTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
            startActivity(intent);

        }
    });


    }
}

I have the same issue. This is happening I think because in the wizard to create a new activity, it creates both an activity.xml file AND a fragment.xml file. Something to do with fragments...

Please see the question I just asked.