Blankj/AndroidUtilCode · info · UnsupportedOperationException

u can't instantiate me...

Error message

u can't instantiate me...

What it means

ClickUtils is a final utility class providing static click/press-effect helpers; its private constructor throws UnsupportedOperationException('u can't instantiate me...') to prevent construction. The throw is an intentional guard reachable only via reflection, because the class is final and the constructor is private.

Source

Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/ClickUtils.java:53

public class ClickUtils {

    private static final int   PRESSED_VIEW_SCALE_TAG           = -1;
    private static final float PRESSED_VIEW_SCALE_DEFAULT_VALUE = -0.06f;

    private static final int   PRESSED_VIEW_ALPHA_TAG           = -2;
    private static final int   PRESSED_VIEW_ALPHA_SRC_TAG       = -3;
    private static final float PRESSED_VIEW_ALPHA_DEFAULT_VALUE = 0.8f;

    private static final int   PRESSED_BG_ALPHA_STYLE         = 4;
    private static final float PRESSED_BG_ALPHA_DEFAULT_VALUE = 0.9f;

    private static final int   PRESSED_BG_DARK_STYLE         = 5;
    private static final float PRESSED_BG_DARK_DEFAULT_VALUE = 0.9f;

    private static final long DEBOUNCING_DEFAULT_VALUE = 1000;

    private ClickUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * Apply scale animation for the views' click.
     *
     * @param views The views.
     */
    public static void applyPressedViewScale(final View... views) {
        applyPressedViewScale(views, null);
    }

    /**
     * Apply scale animation for the views' click.
     *
     * @param views        The views.
     * @param scaleFactors The factors of scale for the views.
     */
    public static void applyPressedViewScale(final View[] views, final float[] scaleFactors) {

View on GitHub (pinned to 7b4caf9e54)

Solutions

  1. Call static methods directly (e.g., ClickUtils.applyPressedViewScale(view)) and never instantiate.
  2. Exclude the constructor from coverage or rely on the coverage helper.
  3. If testing the guard, assert UnsupportedOperationException rather than trying to succeed.
  4. Remove reflective newInstance() calls against ClickUtils.class.
Defensive patterns

Strategy: validation

Validate before calling

// Never instantiate; call static methods directly.
ClickUtils.applyPressedViewScale(view);

Try / catch

try {
    Constructor<ClickUtils> c = ClickUtils.class.getDeclaredConstructor();
    c.setAccessible(true);
    c.newInstance();
} catch (UnsupportedOperationException | InvocationTargetException e) {
    // expected: instantiation is forbidden by design
}

Prevention

When it happens

Trigger: Reflectively invoking the private constructor (setAccessible(true) + newInstance()); coverage or generic reflection tooling that instantiates every class; UI frameworks that auto-construct helper classes.

Common situations: Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests across a package; DI/serialization frameworks attempting default construction.

Related errors


AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14). Data as JSON: /api/errors/d515fe5d44bc83bf. Report an issue: GitHub.