Null pointer error with hideSoftInputFromWindow

后端 未结 14 763
逝去的感伤
逝去的感伤 2020-12-25 11:32

I get a null pointer exception at this row:

public void hideKeyboard(){ 
InputMethodManager inputManager = (InputMethodManager)            
            this.         


        
14条回答
  •  忘掉有多难
    2020-12-25 12:04

    try this:

    public void hideKeyboard(){ 
    InputMethodManager inputManager = (InputMethodManager)            
                this.getSystemService(Context.INPUT_METHOD_SERVICE);    
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    }
    

提交回复
热议问题