I get a null pointer exception at this row:
public void hideKeyboard(){
InputMethodManager inputManager = (InputMethodManager)
this.
Everybody above correctly pointed that the getWindowToken() was returning null.
I was using the default code getCurrentFocus().getWindowToken() to hide keyboard when I encountered the same issue.
I then realized that as there's no View obtaining the focus I got the NullPointerException.
We can change the above to:
anyView.getWindowToken()
where anyView is simply any view in your layout.