Tencent/QMUI_Android · error · NullPointerException
Parameter:listener must not be null
Error message
Parameter:listener must not be null
What it means
The same null-check pattern as the activity parameter: setVisibilityEventListener also requires a non-null KeyboardVisibilityEventListener to receive callbacks. A null listener is rejected with this NullPointerException before the global layout listener is installed.
Source
Thrown at qmui/src/main/java/com/qmuiteam/qmui/util/QMUIKeyboardHelper.java:155
});
}
/**
* Set keyboard visibility change event listener.
*
* @param activity Activity
* @param listener KeyboardVisibilityEventListener
*/
@SuppressWarnings("deprecation")
public static void setVisibilityEventListener(final Activity activity,
final KeyboardVisibilityEventListener listener) {
if (activity == null) {
throw new NullPointerException("Parameter:activity must not be null");
}
if (listener == null) {
throw new NullPointerException("Parameter:listener must not be null");
}
final View activityRoot = QMUIViewHelper.getActivityRoot(activity);
final ViewTreeObserver.OnGlobalLayoutListener layoutListener =
new ViewTreeObserver.OnGlobalLayoutListener() {
private final Rect r = new Rect();
private final int visibleThreshold = Math.round(
QMUIDisplayHelper.dp2px(activity, KEYBOARD_VISIBLE_THRESHOLD_DP));
private boolean wasOpened = false;
@Override
public void onGlobalLayout() {
activityRoot.getWindowVisibleDisplayFrame(r);
View on GitHub (pinned to 026e7d4866)
Solutions
- Pass a concrete listener instance; create it inline if the callback is optional.
- Null-check the listener and skip registration when it isn't ready yet.
- Ensure the listener field is initialized before this call (constructor or onCreate).
- If the callback truly is optional, wrap it in a no-op implementation instead of null.
Example fix
// before
QMUIKeyboardHelper.setVisibilityEventListener(activity, mListener); // mListener not yet set
// after
if (activity != null && mListener != null) {
QMUIKeyboardHelper.setVisibilityEventListener(activity, mListener);
} Defensive patterns
Strategy: validation
Validate before calling
if (activity != null && listener != null) {
QMUIKeyboardHelper.setVisibilityEventListener(activity, listener);
} Type guard
boolean isValidListener(KeyboardVisibilityEventListener l) { return l != null; } Try / catch
try {
QMUIKeyboardHelper.setVisibilityEventListener(activity, listener);
} catch (NullPointerException e) {
Log.w(TAG, "listener not ready for keyboard registration", e);
} Prevention
- Initialize callback fields before any registration call (constructor/onCreate).
- Pass an inline listener literal rather than a possibly-unassigned field.
- Use Optional/no-op default implementations when the callback is optional.
- Run lint/annotations (@NonNull/@Nullable) to catch null listener arguments at compile time.
When it happens
Trigger: Calling QMUIKeyboardHelper.setVisibilityEventListener(activity, null), or passing a field/callback reference that is still null at call time.
Common situations: Callback fields initialized asynchronously (e.g. set later by DI or a presenter) before the helper call, or refactoring that removed listener creation but kept the call.
Related errors
- Parameter:activity must not be null
- Not support the type: %s
- topView must implement from IQMUIContinuousNestedTopView
- bottomView must implement from IQMUIContinuousNestedBottomVi
- delegateView must be a instance of View
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/d53fd105738fddad.
Report an issue: GitHub.