Skip to content Skip to sidebar Skip to footer

Java.lang.illegalargumentexception: Rect Should Intersect With Child's Bounds

In Android Studio after starting a new project, and selecting a Tabbed Activity, after the project is build, I get this error in the Android Monitor: E/AndroidRuntime: FATAL EXCEPT

Solution 1:

After updating the new appcompat version to 24.2.1 i had the same bug, Try to lower the version to 24.1.1 or even to a stable 23 version.

Solution 2:

In my case the problem was caused because of FloatingActionButton.Behavior.

Here the code inside coordinator layout

  if (behavior != null && behavior.getInsetDodgeRect(this, child, rect)) {
        // Make sure that it intersects the views bounds
        if (!rect.intersect(child.getLeft(), child.getTop(),
                child.getRight(), child.getBottom())) {
            throw new IllegalArgumentException("Rect should intersect with child's bounds.");
        }
    }

And here the code inside of FloatingActionButton.Behavior

@OverridepublicbooleangetInsetDodgeRect(@NonNull CoordinatorLayout parent,
            @NonNull FloatingActionButton child, @NonNull Rect rect) {
        // Since we offset so that any internal shadow padding isn't shown, we need to make// sure that the shadow isn't used for any dodge inset calculationsfinalRectshadowPadding= child.mShadowPadding;
        rect.set(child.getLeft() + shadowPadding.left,
                child.getTop() + shadowPadding.top,
                child.getRight() - shadowPadding.right,
                child.getBottom() - shadowPadding.bottom);
        returntrue;
    }

As you can see getInsetDodgeRect was returning true and by some reason rect was not intersecting. This causes the problem.

The workaround.

I could fix it just extending the behavior and overwriting the method getInsetDodgeRect to return false;

publicclassScrollAwareFABBehaviorextendsFloatingActionButton.Behavior {
...
@OverridepublicbooleangetInsetDodgeRect(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton child, @NonNull Rect rect) {
    super.getInsetDodgeRect(parent, child, rect);
    returnfalse;
}
...

Solution 3:

It's a bug introduced in support library 24.2.1, see here.

Known workarounds:

  • Downgrade to a different support library version

Solution 4:

The bug have been fixed in 25.1.0

Solution 5:

The problem is present when used a layout based on a old version appcompat, look the layout xml file and edit it. Erase tools:context atribut and the problem is solved.

Post a Comment for "Java.lang.illegalargumentexception: Rect Should Intersect With Child's Bounds"