java - Applicaton has stopped error after create instance of AlertDialog -


i have project classes.

one class extends activity has button. oncreate method of class.

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.select_car); /////// codes , behaviors here  

till arrive @ 1 of methods acts on button.
when the button clicked, data inserted db, before want confirmation end user selected corrected or not.
first want set positive answer, here did in specific button.

            choose.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) { //i want confirm end user, did                 final alertdialog.builder builder = new alertdialog.builder(getapplication());                 builder.setmessage("are sure this?")                         .settitle("alert");                 builder.setpositivebutton("ok", new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                     }                 }); alertdialog dialog = builder.create();  // data insert db      }             }); 

when run project , achieve class, got error in android device :

unfortunately "myapplicationname" has stopped.

and log android-studio

10-22 18:36:17.910  14478-14478/com.theonlyone.behtakapp e/androidruntime﹕ fatal exception: main     process: com.theonlyone.behtakapp, pid: 14478     android.view.windowmanager$badtokenexception: unable add window -- token null not application             @ android.view.viewrootimpl.setview(viewrootimpl.java:660)             @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:261)             @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69)             @ android.app.dialog.show(dialog.java:286)             @ android.app.alertdialog$builder.show(alertdialog.java:951)             @ com.theonlyone.behtakapp.car$5.onclick(car.java:306)             @ android.view.view.performclick(view.java:4470)             @ android.view.view$performclick.run(view.java:18796)             @ android.os.handler.handlecallback(handler.java:808)             @ android.os.handler.dispatchmessage(handler.java:103)             @ android.os.looper.loop(looper.java:193)             @ android.app.activitythread.main(activitythread.java:5299)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:825)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:641)             @ dalvik.system.nativestart.main(native method) 

what should do?

$badtokenexception: unable add window -- token null not application

because passing application context using getapplication() in alertdialog.builder.

to show alert current activity running pass car.this or v.getcontext() in alertdialog.builder


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -