New to android, can't switch between intents -
this question has answer here:
i have button, , when clicked i'd load new view.
i using main activity class
public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } public void buttonpressed(view v){ intent = new intent(this, switchedactivity.class); startactivity(i); } }
and i'd load other activity
public class switchedactivity extends activity { protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_two); } }
so should happen, click button in activity_main.xml, , loads layout activity_two.xml.
the problem is, when click button, app crashes.
i logcat stack trace:
08-18 11:36:09.078: e/androidruntime(1232): fatal exception: main 08-18 11:36:09.078: e/androidruntime(1232): process: com.johncorser.myapp, pid: 1232 08-18 11:36:09.078: e/androidruntime(1232): java.lang.illegalstateexception: not execute method of activity 08-18 11:36:09.078: e/androidruntime(1232): @ android.view.view$1.onclick(view.java:3823) 08-18 11:36:09.078: e/androidruntime(1232): @ android.view.view.performclick(view.java:4438) 08-18 11:36:09.078: e/androidruntime(1232): @ android.view.view$performclick.run(view.java:18422) 08-18 11:36:09.078: e/androidruntime(1232): @ android.os.handler.handlecallback(handler.java:733) 08-18 11:36:09.078: e/androidruntime(1232): @ android.os.handler.dispatchmessage(handler.java:95) 08-18 11:36:09.078: e/androidruntime(1232): @ android.os.looper.loop(looper.java:136) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.activitythread.main(activitythread.java:5017) 08-18 11:36:09.078: e/androidruntime(1232): @ java.lang.reflect.method.invokenative(native method) 08-18 11:36:09.078: e/androidruntime(1232): @ java.lang.reflect.method.invoke(method.java:515) 08-18 11:36:09.078: e/androidruntime(1232): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 08-18 11:36:09.078: e/androidruntime(1232): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 08-18 11:36:09.078: e/androidruntime(1232): @ dalvik.system.nativestart.main(native method) 08-18 11:36:09.078: e/androidruntime(1232): caused by: java.lang.reflect.invocationtargetexception 08-18 11:36:09.078: e/androidruntime(1232): @ java.lang.reflect.method.invokenative(native method) 08-18 11:36:09.078: e/androidruntime(1232): @ java.lang.reflect.method.invoke(method.java:515) 08-18 11:36:09.078: e/androidruntime(1232): @ android.view.view$1.onclick(view.java:3818) 08-18 11:36:09.078: e/androidruntime(1232): ... 11 more 08-18 11:36:09.078: e/androidruntime(1232): caused by: android.content.activitynotfoundexception: unable find explicit activity class {com.johncorser.myapp/com.johncorser.myapp.switchedactivity}; have declared activity in androidmanifest.xml? 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1628) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.instrumentation.execstartactivity(instrumentation.java:1424) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.activity.startactivityforresult(activity.java:3424) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.activity.startactivityforresult(activity.java:3385) 08-18 11:36:09.078: e/androidruntime(1232): @ android.support.v4.app.fragmentactivity.startactivityforresult(fragmentactivity.java:839) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.activity.startactivity(activity.java:3627) 08-18 11:36:09.078: e/androidruntime(1232): @ android.app.activity.startactivity(activity.java:3595) 08-18 11:36:09.078: e/androidruntime(1232): @ com.johncorser.myapp.mainactivity.buttonpressed(mainactivity.java:40) 08-18 11:36:09.078: e/androidruntime(1232): ... 14 more
fair warning, i'm doing stupid, i'm new.
i pretty did not declare second activity in androidmanifest.xml
file.
you should have in manifest:
<application ... > <activity android:name=".mainactivity" ... > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".switchedactivity" ... > </activity> ... </application>
Comments
Post a Comment