Please correct my Android Java code using an onkey/onclick listeners on my Dialog -
i triggering dialog password verification , cant figure out why cause exception when incorrect password entered. need jedi masters assist padewan.
@override private void launchpwddialog(){ layoutinflater li = layoutinflater.from(context); view promptsview = li.inflate(r.layout.prompts, null); alertdialog.builder alertdialogbuilder = new alertdialog.builder(context); alertdialogbuilder.setview(promptsview); final edittext userinput = (edittext) promptsview.findviewbyid(r.id.edtpasswordinput); alertdialogbuilder .setcancelable(true) .setpositivebutton("finish", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id){ if (userinput.gettext().tostring().compareto(stradminpassword) == 0){ disablekioskmode(); } else{ log.i(tag, "function launchpwddialog - admin password incorrect. user entered: " + edt.gettext().tostring()); toast.maketext(getbasecontext(), "incorrect password", toast.length_short).show(); } } }) .setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id){ disablekioskmode(); dialog.dismiss(); } }) .setonkeylistener(new dialoginterface.onkeylistener() { @override public boolean onkey(dialoginterface dialog, int keycode, keyevent event){ if (event.getkeycode() == keyevent.keycode_enter) if (userinput.gettext().tostring().compareto(stradminpassword) == 0) { disablekioskmode(); userinput.settext(""); dialog.dismiss(); } else { log.i(tag, "function launchpwddialog - admin password incorrect. user entered: " + edt.gettext().tostring()); toast.maketext(getbasecontext(), "incorrect password", toast.length_short).show(); if (currentattempt % maxattempts == 0) { log.i(tag, "you unauthorised access feature."); toast.maketext(getbasecontext(), "you unauthorised access feature.", toast.length_short).show(); finish(); } } return false; } }); alertdialog alertdialog = alertdialogbuilder.create(); alertdialog.show(); }
i've got executing disablekioskmode() function upon successful verification of password if enter nothing or wrong password, crashes. not sure if helps heres logcat:
06-01 05:55:24.910 12311 12311 d androidruntime com.androiddev.kiosk shutting down vm 06-01 05:55:24.910 12311 12311 w dalvikvm com.androiddev.kiosk threadid=1: thread exiting uncaught exception (group=0x41759c08) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk fatal exception: main 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk process: com.androiddev.kiosk, pid: 12311 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk java.lang.nullpointerexception 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ com.androiddev.kiosk.kiosklauncher$100000000.onclick(kiosklauncher.java:413) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:170) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ android.os.handler.dispatchmessage(handler.java:102) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ android.os.looper.loop(looper.java:146) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ android.app.activitythread.main(activitythread.java:5653) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ java.lang.reflect.method.invokenative(native method) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ java.lang.reflect.method.invoke(method.java:515) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1291) 06-01 05:55:24.915 12311 12311 e androidruntime com.androiddev.kiosk @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1107)
check if userinput.gettext().tostring()
null before making operations on it.
Comments
Post a Comment