java - Cant start a dialog activity from a button in another activity -
i trying start new activity dialog activity putting intent on button activity. whenever try , press button, activity unfotunately closes.
main activity.java
public class mainactivity extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button ab = (button) findviewbyid(r.id.button1); ab.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub intent intent = new intent(mainactivity.this, newdialog.class); startactivity(intent); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public void side(view view){ android.support.v4.app.fragmentmanager fm1 = getsupportfragmentmanager(); newdialog newdialog = new newdialog(); newdialog.show(fm1, "sidedialog"); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ }
newdialog.java
public class newdialog extends dialogfragment{ public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){ final view view = inflater.inflate(r.layout.activity_new_dialog, container); getdialog().requestwindowfeature(window.feature_no_title); return view; } }
added logcat:
05-29 22:37:36.472: d/dalvikvm(26806): late-enabling checkjni 05-29 22:37:36.762: d/activitythread(26806): settargetheaputilization:0.25 05-29 22:37:36.762: d/activitythread(26806): settargetheapidealfree:8388608 05-29 22:37:36.762: d/activitythread(26806): settargetheapconcurrentstart:2097152 05-29 22:37:39.172: d/libegl(26806): loaded /system/lib/egl/libegl_adreno200.so 05-29 22:37:39.222: d/libegl(26806): loaded /system/lib/egl/libglesv1_cm_adreno200.so 05-29 22:37:39.322: d/libegl(26806): loaded /system/lib/egl/libglesv2_adreno200.so 05-29 22:37:39.362: i/adreno200-egl(26806): <qegldrvapi_eglinitialize:299>: egl 1.4 qualcomm build: au_linux_android_jb_rel_2.0.3.1_rb1.04.01.01.45.000_msm8625_jb_rel_2.0.3.1_merge_release_au (merge) 05-29 22:37:39.362: i/adreno200-egl(26806): build date: 03/28/13 thu 05-29 22:37:39.362: i/adreno200-egl(26806): local branch: 05-29 22:37:39.362: i/adreno200-egl(26806): remote branch: m/jb_rel_2.0.3.1 05-29 22:37:39.362: i/adreno200-egl(26806): local patches: none 05-29 22:37:39.362: i/adreno200-egl(26806): reconstruct branch: nothing 05-29 22:37:39.452: d/openglrenderer(26806): enabling debug mode 0 05-29 22:37:43.822: d/androidruntime(26806): shutting down vm 05-29 22:37:43.822: w/dalvikvm(26806): threadid=1: thread exiting uncaught exception (group=0x40fd4438) 05-29 22:37:44.022: e/androidruntime(26806): fatal exception: main 05-29 22:37:44.022: e/androidruntime(26806): java.lang.runtimeexception: unable instantiate activity componentinfo{com.example.createdialog/com.example.createdialog.newdialog}: java.lang.classcastexception: com.example.createdialog.newdialog cannot cast android.app.activity 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread.performlaunchactivity(activitythread.java:2038) 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2139) 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread.access$700(activitythread.java:143) 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread$h.handlemessage(activitythread.java:1241) 05-29 22:37:44.022: e/androidruntime(26806): @ android.os.handler.dispatchmessage(handler.java:99) 05-29 22:37:44.022: e/androidruntime(26806): @ android.os.looper.loop(looper.java:137) 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread.main(activitythread.java:4963) 05-29 22:37:44.022: e/androidruntime(26806): @ java.lang.reflect.method.invokenative(native method) 05-29 22:37:44.022: e/androidruntime(26806): @ java.lang.reflect.method.invoke(method.java:511) 05-29 22:37:44.022: e/androidruntime(26806): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) 05-29 22:37:44.022: e/androidruntime(26806): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 05-29 22:37:44.022: e/androidruntime(26806): @ dalvik.system.nativestart.main(native method) 05-29 22:37:44.022: e/androidruntime(26806): caused by: java.lang.classcastexception: com.example.createdialog.newdialog cannot cast android.app.activity 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.instrumentation.newactivity(instrumentation.java:1068) 05-29 22:37:44.022: e/androidruntime(26806): @ android.app.activitythread.performlaunchactivity(activitythread.java:2029) 05-29 22:37:44.022: e/androidruntime(26806): ... 11 more
i might wrong here, far know, can't start intent
passing dialogfragment
, should pass activity
. here's what's wrong:
intent intent = new intent(mainactivity.this, newdialog.class); startactivity(intent);
since newdialog
declared dialogfragment
, not activity
subclass.
if trying show dialog, should do:
newdialog dialog = newdialog(); // use getsupportfragmentmanager() if using support fragments instead of native fragments, or // use getchildfragmentmanager() if code inside fragment rather activity dialog.show(getfragmentmanager(), "pass-any-string-here");
Comments
Post a Comment