android - Alert Dialog error -
i'm trying watch alertdialog 2 options: cámara , galería. when run app closes message "unfortunately, mapalugares has closed".
the logcat message is:
08-15 20:37:02.960: e/androidruntime(5377): fatal exception: main 08-15 20:37:02.960: e/androidruntime(5377): android.view.windowmanager$badtokenexception: unable add window -- token null not application 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.viewrootimpl.setview(viewrootimpl.java:521) 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:301) 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:215) 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:140) 08-15 20:37:02.960: e/androidruntime(5377): @ android.app.dialog.show(dialog.java:289) 08-15 20:37:02.960: e/androidruntime(5377): @ com.app.mapa.insertarlugar$1.onclick(insertarlugar.java:62) 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.view.performclick(view.java:3521) 08-15 20:37:02.960: e/androidruntime(5377): @ android.view.view$performclick.run(view.java:14185) 08-15 20:37:02.960: e/androidruntime(5377): @ android.os.handler.handlecallback(handler.java:605) 08-15 20:37:02.960: e/androidruntime(5377): @ android.os.handler.dispatchmessage(handler.java:92) 08-15 20:37:02.960: e/androidruntime(5377): @ android.os.looper.loop(looper.java:137) 08-15 20:37:02.960: e/androidruntime(5377): @ android.app.activitythread.main(activitythread.java:4464) 08-15 20:37:02.960: e/androidruntime(5377): @ java.lang.reflect.method.invokenative(native method) 08-15 20:37:02.960: e/androidruntime(5377): @ java.lang.reflect.method.invoke(method.java:511) 08-15 20:37:02.960: e/androidruntime(5377): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:822) 08-15 20:37:02.960: e/androidruntime(5377): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:589) 08-15 20:37:02.960: e/androidruntime(5377): @ dalvik.system.nativestart.main(native method) 08-15 20:37:05.210: i/activitythread(5573): pub com.app.mapa.mcprovider: com.app.mapa.mcprovider 08-15 20:37:05.570: d/memalloc(5573): /dev/pmem: mapped buffer base:0x5127b000 size:2826240 offset:1290240 fd:51 08-15 20:37:05.620: e/adreno200-es20(5573): <qgl2drvapi_gluseprogram:1318>: **** 5573: gluseprogram(3) 08-15 20:37:05.650: e/adreno200-es20(5573): <qgl2drvapi_gluseprogram:1318>: **** 5573: gluseprogram(6) 08-15 20:37:05.670: d/memalloc(5573): /dev/pmem: mapped buffer base:0x516f7000 size:4362240 offset:2826240 fd:58
the code:
public class insertarlugar extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_insertarlugar); imagebutton imgbutton; imgbutton = (imagebutton) findviewbyid(r.id.imgbutton); edittext titlugar; edittext desclugar; titlugar = (edittext) findviewbyid(r.id.edit_titulo_lugar); string tlugar = titlugar.gettext().tostring(); desclugar = (edittext) findviewbyid(r.id.edit_descripcion_lugar); string dlugar = desclugar.gettext().tostring(); imgbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { final string[] items = {"cámara", "galería"}; alertdialog.builder builder = new alertdialog.builder(getapplicationcontext()); builder.settitle("foto"); builder.setitems(items, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int item) { toast.maketext(insertarlugar.this, "click\n" + item, toast.length_short).show(); } }); alertdialog alert = builder.create(); alert.show(); } }); }
what's wrong?
thanks.
change line
alertdialog.builder(getapplicationcontext());
to
alertdialog.builder(insertarlugar.this);
a dialog
created on activity
want use context
create , not application's context
. true ui
objects, far understand context
. may work objects such toast
but, in opinion, better try , use correct context
here activity
's.
and see this answer when use context
Comments
Post a Comment