Unfortunately <app name> Has Stopped

  • Replies:2
Sampa Musonda
  • Forum posts: 1

Apr 22, 2014, 12:11:04 AM via Website

I am a rookie android developer and been following android programming tutorials. Everything runs smoothly until i input java code, i get this run-time error "Unfortunately has stopped.

Here is my Activity.Java

enter code here

package com.example.beentheredonethat;

import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.TextView; import android.os.Build;

public class QuizSplashActivity extends ActionBarActivity {

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


    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
    }
    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    Animation fade= AnimationUtils.loadAnimation(this,R.anim.abc_fade_in);
    logo1.startAnimation(fade);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.quiz_splash, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_quiz_splash, container, false);
        return rootView;
    }
}

}

Here is my logcat 04-21 18:07:55.557: D/AndroidRuntime(1429): Shutting down VM 04-21 18:07:55.557: W/dalvikvm(1429): threadid=1: thread exiting with uncaught exception (group=0xb2b0cba8) 04-21 18:07:55.587: E/AndroidRuntime(1429): FATAL EXCEPTION: main 04-21 18:07:55.587: E/AndroidRuntime(1429): Process: com.example.beentheredonethat, PID: 1429 04-21 18:07:55.587: E/AndroidRuntime(1429): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.beentheredonethat/com.example.beentheredonethat.QuizSplashActivity}: java.lang.NullPointerException 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread.access$800(ActivityThread.java:135) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.os.Handler.dispatchMessage(Handler.java:102) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.os.Looper.loop(Looper.java:136) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread.main(ActivityThread.java:5017) 04-21 18:07:55.587: E/AndroidRuntime(1429): at java.lang.reflect.Method.invokeNative(Native Method) 04-21 18:07:55.587: E/AndroidRuntime(1429): at java.lang.reflect.Method.invoke(Method.java:515) 04-21 18:07:55.587: E/AndroidRuntime(1429): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 04-21 18:07:55.587: E/AndroidRuntime(1429): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 04-21 18:07:55.587: E/AndroidRuntime(1429): at dalvik.system.NativeStart.main(Native Method) 04-21 18:07:55.587: E/AndroidRuntime(1429): Caused by: java.lang.NullPointerException 04-21 18:07:55.587: E/AndroidRuntime(1429): at com.example.beentheredonethat.QuizSplashActivity.onCreate(QuizSplashActivity.java:25) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.Activity.performCreate(Activity.java:5231) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 04-21 18:07:55.587: E/AndroidRuntime(1429): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 04-21 18:07:55.587: E/AndroidRuntime(1429): ... 11 more

Reply
OMG! Brews Games
  • Forum posts: 1

Apr 24, 2014, 11:44:07 PM via Website

You are following a null pointer -- notice the java.lang.NullPointerException in the stack trace. My guess is that findViewByID was unable to find R.id.TextViewTopTitle in the R.layout.activity_quiz_splash layout file. This resulted in logo1 being null, and a crash occurring when you attempted to run its method with 'logo1.startAnimation(fade)'.

I recommend you run your program in debug mode and try to confirm that this is the line of code which is resulting in the NullPointerException, and go from there.

Reply
Satheesh Kumar
  • Forum posts: 20

May 1, 2014, 4:32:16 PM via Website

There is a NullPointerException at line no 25.
It is difficult to find the error without seeing the whole program.

Reply