At first the code is:
private void hideKeyboard()
{
View view = getCurrentFocus();
if (view != null)
{
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
the warning message is :
Method invocation 'hideSoftInputFromWindow' may produce 'java.lang.NullPointerException'
so I changed code under the hint to:
private void hideKeyboard()
{
View view = getCurrentFocus();
if (view != null)
{
((InputMethodManager) Objects.requireNonNull(getSystemService(Context.INPUT_METHOD_SERVICE)))
.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
this time the warning message is:
call requires api level 19 current min is 16 java.util.objects#requirenonnull
How can I figure out? Thank you.