Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Android Activity Causes Crash
    text
    copied!<p>I started creating a new activity for my android app, and as I was testing it I encountered a problem. As i touched the button to go to the new activity, the app would crash and send be back to the main activity. </p> <p>Here is my activity with the button that goes to the new activity:</p> <pre><code>package brian.android.testgame; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class BeginnerLevelSelector extends Activity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.beginner_level_selector); Button level1button = (Button) findViewById(R.id.bl1); final Intent level1activity = new Intent(this, Level1Activity.class); level1button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(level1activity); } }); } } </code></pre> <p>Here is my activity that crashes when I try to start it (yes, that is all I typed before I found the problem)</p> <pre><code>package brian.android.testgame; import android.app.Activity; import android.os.Bundle; public class Level1Activity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); } } </code></pre> <p>And here is my log when the app crashes:</p> <pre><code>05-06 21:07:29.085: E/AndroidRuntime(20391): FATAL EXCEPTION: main 05-06 21:07:29.085: E/AndroidRuntime(20391): android.content.ActivityNotFoundException: Unable to find explicit activity class {brian.android.testgame/brian.android.testgame.Level1Activity}; have you declared this activity in your AndroidManifest.xml? 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1634) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.app.Activity.startActivityForResult(Activity.java:3244) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.app.Activity.startActivity(Activity.java:3351) 05-06 21:07:29.085: E/AndroidRuntime(20391): at brian.android.testgame.BeginnerLevelSelector$1.onClick(BeginnerLevelSelector.java:22) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.view.View.performClick(View.java:3549) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.view.View$PerformClick.run(View.java:14400) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.os.Handler.handleCallback(Handler.java:605) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.os.Handler.dispatchMessage(Handler.java:92) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.os.Looper.loop(Looper.java:154) 05-06 21:07:29.085: E/AndroidRuntime(20391): at android.app.ActivityThread.main(ActivityThread.java:4944) 05-06 21:07:29.085: E/AndroidRuntime(20391): at java.lang.reflect.Method.invokeNative(Native Method) 05-06 21:07:29.085: E/AndroidRuntime(20391): at java.lang.reflect.Method.invoke(Method.java:511) 05-06 21:07:29.085: E/AndroidRuntime(20391): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 05-06 21:07:29.085: E/AndroidRuntime(20391): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-06 21:07:29.085: E/AndroidRuntime(20391): at dalvik.system.NativeStart.main(Native Method) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload