gyf-dev/ImmersionBar · error · IllegalArgumentException

View参数不能为空

Error message

View参数不能为空

What it means

addViewSupportTransformColorInt registers a View whose color should transform along with the status bar. It validates that the view is non-null and throws IllegalArgumentException("View参数不能为空") ("view parameter cannot be empty") otherwise, since a null view cannot be keyed into the internal viewMap.

Solutions

  1. Pass a valid, already-inflated View reference (ensure findViewById/bindings ran first)
  2. Null-check the view before configuring the bar
  3. Move the call after setContentView/onViewCreated

Example fix

// before
bar.addViewSupportTransformColorInt(toolbar, Color.TRANSPARENT); // toolbar null
// after
View toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
    bar.addViewSupportTransformColorInt(toolbar, Color.TRANSPARENT);
}
Defensive patterns

Strategy: validation

Validate before calling

if (view != null) { bar.addViewSupportTransformColorInt(view, color); }

Type guard

View requireView(View v) { if (v == null) throw new IllegalStateException("view not inflated"); return v; }

Try / catch

try { bar.addViewSupportTransformColorInt(view, color); } catch (IllegalArgumentException e) { Log.e(TAG, "null view for transform color", e); }

Prevention

When it happens

Trigger: Calling addViewSupportTransformColorInt(null, someColor), often when the view reference comes from findViewById that returned null or a lazily-inflated field still null.

Common situations: View not yet inflated when the bar is configured; wrong layout id causing findViewById to return null; Kotlin lateinit/Jetpack binding accessed too early.

Related errors


AI-assisted analysis of gyf-dev/ImmersionBar@8cac10cd83 (2026-09-08). Data as JSON: /api/errors/1fb4c66991c516cf. Report an issue: GitHub.

Appendix: source

Thrown at immersionbar/src/main/java/com/gyf/immersionbar/ImmersionBar.java:3762

     * @return the immersion bar
     */
    public ImmersionBar addViewSupportTransformColor(View view, String viewColorBeforeTransform,
                                                     String viewColorAfterTransform) {
        return this.addViewSupportTransformColorInt(view,
                Color.parseColor(viewColorBeforeTransform),
                Color.parseColor(viewColorAfterTransform));
    }

    /**
     * Add 颜色变换支持View
     *
     * @param view                    the view
     * @param viewColorAfterTransform the view color after transform
     * @return the immersion bar
     */
    public ImmersionBar addViewSupportTransformColorInt(View view, @ColorInt int viewColorAfterTransform) {
        if (view == null) {
            throw new IllegalArgumentException("View参数不能为空");
        }
        Map<Integer, Integer> map = new HashMap<>();
        map.put(mBarParams.statusBarColor, viewColorAfterTransform);
        mBarParams.viewMap.put(view, map);
        return this;
    }

    /**
     * Add 颜色变换支持View
     *
     * @param view                     the view
     * @param viewColorBeforeTransform the view color before transform
     * @param viewColorAfterTransform  the view color after transform
     * @return the immersion bar
     */
    public ImmersionBar addViewSupportTransformColorInt(View view, @ColorInt int viewColorBeforeTransform,
                                                        @ColorInt int viewColorAfterTransform) {
        if (view == null) {

View on GitHub (pinned to 8cac10cd83)