android - time picker dialog is not displaying, give Fathal Exception? -
i want add fields dynamically, when click add button add row exittext,settime button,remove button. when click remove button row removed ok, problem when click set time button give fatal exception, dialog not displayed. please check code. have problem @ settime button in code. when click button unfortunately closed.
addmore.setonclicklistener(new onclicklistener() { @suppresslint("inflateparams") @override public void onclick(view v) { // todo auto-generated method stub layoutinflater layoutinflater = (layoutinflater) getbasecontext().getsystemservice(context.layout_inflater_service); final view addview = layoutinflater.inflate(r.layout.row, null); final edittext detext=(edittext)addview.findviewbyid(r.id.txt_dynamic); // button settime in row final button settimebtn=(button)addview.findviewbyid(r.id.settime); settimebtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //************************** // process current time final calendar c = calendar.getinstance(); mhours = c.get(calendar.hour_of_day); mminitue = c.get(calendar.minute); // launch time picker dialog timepickerdialog tpdynamic=new timepickerdialog(getapplicationcontext(), new timepickerdialog.ontimesetlistener() { @override public void ontimeset(timepicker view, int hourofday, int minute) { // todo auto-generated method stub detext.settext(hourofday + ":" + minute); } } , mhours, mminitue, false); tpdynamic.show(); } //************************** }); //button remove button remove=(button)addview.findviewbyid(r.id.remove); remove.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub ((linearlayout)addview.getparent()).removeview(addview); } }); container.addview(addview, 0); } });
my logcat :
11-19 17:06:06.010: e/androidruntime(15357): fatal exception: main 11-19 17:06:06.010: e/androidruntime(15357): android.view.windowmanager$badtokenexception: unable add window -- token null not application 11-19 17:06:06.010: e/androidruntime(15357): @ android.view.viewrootimpl.setview(viewrootimpl.java:571) 11-19 17:06:06.010: e/androidruntime(15357): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:246) 11-19 17:06:06.010: e/androidruntime(15357): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 11-19 17:06:06.010: e/androidruntime(15357): @ android.app.dialog.show(dialog.java:281) 11-19 17:06:06.010: e/androidruntime(15357): @ com.example.medicine.medicinehomeactivity$1$1.onclick(medicinehomeactivity.java:89) 11-19 17:06:06.010: e/androidruntime(15357): @ android.view.view.performclick(view.java:4217) 11-19 17:06:06.010: e/androidruntime(15357): @ android.view.view$performclick.run(view.java:17368) 11-19 17:06:06.010: e/androidruntime(15357): @ android.os.handler.handlecallback(handler.java:725) 11-19 17:06:06.010: e/androidruntime(15357): @ android.os.handler.dispatchmessage(handler.java:92) 11-19 17:06:06.010: e/androidruntime(15357): @ android.os.looper.loop(looper.java:137) 11-19 17:06:06.010: e/androidruntime(15357): @ android.app.activitythread.main(activitythread.java:5039) 11-19 17:06:06.010: e/androidruntime(15357): @ java.lang.reflect.method.invokenative(native method) 11-19 17:06:06.010: e/androidruntime(15357): @ java.lang.reflect.method.invoke(method.java:511) 11-19 17:06:06.010: e/androidruntime(15357): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 11-19 17:06:06.010: e/androidruntime(15357): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 11-19 17:06:06.010: e/androidruntime(15357): @ dalvik.system.nativestart.main(native method)
try using
layoutinflater layoutinflater = (layoutinflater)youractivityname.this.getsystemservice(context.layout_inflater_service);
instead of
layoutinflater layoutinflater = (layoutinflater) getbasecontext().getsystemservice(context.layout_inflater_service);
Comments
Post a Comment