user3831011
user3831011

Reputation: 309

App crashing after creating new activity

So I made a new activity class:

public class TutorialActivity extends ActionBarActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.tutorial, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

And inside a thread I try to open it:

public void run() {
            if(newGame) {
                Intent intent = new Intent(this.activity, TutorialActivity.class);
                this.activity.startActivity(intent);
            }

            while(inGame) {
                try {
                    this.sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

I see the new activity because I see the text I set in it but then it instantly crashes. So it does load the activity but then something happens and it just crashes.

Log:

08-29 23:49:45.242: D/AndroidRuntime(21100): Shutting down VM
08-29 23:49:45.242: E/AndroidRuntime(21100): FATAL EXCEPTION: main
08-29 23:49:45.242: E/AndroidRuntime(21100): Process: com.example.trollacademy, PID: 21100
08-29 23:49:45.242: E/AndroidRuntime(21100): java.lang.RuntimeException: Unable to stop activity {com.example.trollacademy/com.example.trollacademy.MainActivity}: android.util.SuperNotCalledException: Activity {com.example.trollacademy/com.example.trollacademy.MainActivity} did not call through to super.onStop()
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3855)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3908)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread.access$1200(ActivityThread.java:177)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.os.Handler.dispatchMessage(Handler.java:102)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.os.Looper.loop(Looper.java:145)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread.main(ActivityThread.java:5942)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at java.lang.reflect.Method.invoke(Native Method)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at java.lang.reflect.Method.invoke(Method.java:372)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
08-29 23:49:45.242: E/AndroidRuntime(21100): Caused by: android.util.SuperNotCalledException: Activity {com.example.trollacademy/com.example.trollacademy.MainActivity} did not call through to super.onStop()
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.Activity.performStop(Activity.java:6495)
08-29 23:49:45.242: E/AndroidRuntime(21100):    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3852)
08-29 23:49:45.242: E/AndroidRuntime(21100):    ... 10 more

Upvotes: 2

Views: 207

Answers (3)

xiaoyee
xiaoyee

Reputation: 160

Caused by: android.util.SuperNotCalledException: Activity {com.example.trollacademy/com.example.trollacademy.MainActivity} did not call through to super.onStop()

if u override onStop, u should call super.onStop(). I dont know which IDE u use,but if the IDE give u a red line, u should find the reason why it is red,and fix it.
Hope fun

Upvotes: 0

George Rappel
George Rappel

Reputation: 7198

The activity from which you call the new "TutorialActivity" has a wrong implementation of the method onStop().

The methods with tag @Override should always come with a super call, so your onStop method should look somethng like:

@Override
public void onStop(){
    super.onStop(); // THIS LINE IS MISSING ON YOUR CODE

    //Other things you want to do.
}

You didn't post this part of the code of your other activity, but is probably that. You could also edit your question and add this part of the code to help others.

Upvotes: 2

Deleted User
Deleted User

Reputation: 1

To create new activity, you must create new class and defined it in androidManifest.xml.

Upvotes: 0

Related Questions