java - giving null pointer when using InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); -
hi i'm trying input piece of code hide soft keyboard on android, it's returning null pointer.
code:
public void testsettestenvironment (){ solo.clickinlist(4); solo.clickonmenuitem(configvariables.catalogserver); asserttrue(solo.searchtext(configvariables.catalogserverurl)); //enter keycode solo.clickinlist(5); view myedittext = solo.getviews().get(0); inputmethodmanager imm = (inputmethodmanager)getsystemservice(context.input_method_service); imm.hidesoftinputfromwindow(myedittext.getwindowtoken(), inputmethodmanager.hide_implicit_only); solo.entertext(solo.getedittext(0), ""); solo.entertext(0, configvariables.keycode); asserttrue(popupclickbuttonhandler("enter keycode", "ok"));
the logs show:
java.lang.nullpointerexception
thanks.
maybe little bit late hope helpful someone. code bug-prone because relies on focused view window token from.
try using:
inputmethodmanager im = (inputmethodmanager) this.getapplicationcontext().getsystemservice(context.input_method_service); im.hidesoftinputfromwindow(getwindow().getdecorview().getwindowtoken(), inputmethodmanager.hide_not_always);
this code works correctly me.
taken this answer venator85
Comments
Post a Comment