java - Why this alertView does not generate and causes the application to crash? -


i want know wrong code, or missing in code. here scenario:

i have listview , customadapter data derived baseadapter.

i've made custom view each item.

in custom view ( aka cell ) have applied longclicklistener. on pressing cell long time, method of long click gets called successfully. no problems till here.

but moment add code generating alertdialog in method, alterdialog never generate , crash whole application.

i tried creating method outside in class holds alertdialog generation. call outside method longclicklistener's interface method. still same crash.

then tried creating whole alertdialog via runnable , started runnable after 1 second via handler, still alertdialog never generates , causes application crash.

following code till now:

void called()     {         handler h = new handler();         runnable r = new runnable(){             @override             public void run()             {                 log.d("mx", "about run!");                 alertdialog.builder alertdialogbuilder = new alertdialog.builder(foldercell.this.getcontext());                 alertdialogbuilder                     .settitle("title")                     .setmessage("message")                     .setcancelable(false)                     .setnegativebutton("ok",new dialoginterface.onclicklistener() {                         public void onclick(dialoginterface dialog,int id) {                             dialog.cancel();                         }                     });                      alertdialog alertdialog = alertdialogbuilder.create();                     alertdialog.show();             }         };          h.postdelayed(r, 1000);     }      @override     public boolean onlongclick(view arg0) {         // todo auto-generated method stub         log.d("mx", "long clicked!");          this.called();          return true;     } 

crash log:

08-23 23:40:39.734: e/androidruntime(32390): fatal exception: main 08-23 23:40:39.734: e/androidruntime(32390): android.view.windowmanager$badtokenexception: unable add window -- token null not application 08-23 23:40:39.734: e/androidruntime(32390):    @ android.view.viewrootimpl.setview(viewrootimpl.java:589) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:326) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:224) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:149) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.app.dialog.show(dialog.java:277) 08-23 23:40:39.734: e/androidruntime(32390):    @ com.rdmteq.pic_measure.foldercell$2.run(foldercell.java:216) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.os.handler.handlecallback(handler.java:615) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.os.handler.dispatchmessage(handler.java:92) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.os.looper.loop(looper.java:137) 08-23 23:40:39.734: e/androidruntime(32390):    @ android.app.activitythread.main(activitythread.java:4794) 08-23 23:40:39.734: e/androidruntime(32390):    @ java.lang.reflect.method.invokenative(native method) 08-23 23:40:39.734: e/androidruntime(32390):    @ java.lang.reflect.method.invoke(method.java:511) 08-23 23:40:39.734: e/androidruntime(32390):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:789) 08-23 23:40:39.734: e/androidruntime(32390):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:556) 08-23 23:40:39.734: e/androidruntime(32390):    @ dalvik.system.nativestart.main(native method) 

additional info on foldercell in heirarchy

mainactivity (activity class)     |     contains--> listview (listview class)             |             --> customadapter (baseadapter class) , set listview                    |                                        contains-> foldercell (relativelayout class) generated in getview(..)  

can me ?

you can try use foldercell.this instead of foldercell.this.getcontext() , check if work in main thread.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -