Blankj/AndroidUtilCode · error · IllegalArgumentException
Array has incompatible type: {}
Error message
Array has incompatible type: {} What it means
Thrown by ArrayUtils.toString when the argument is non-null but not one of the supported array types (Object[], boolean[], byte[], char[], short[], int[], long[], float[], double[]). The method dispatches on instanceof for each array kind and throws as a terminal fallback. null is handled separately (returns "null").
Source
Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java:2137
return Arrays.deepToString((Object[]) array);
} else if (array instanceof boolean[]) {
return Arrays.toString((boolean[]) array);
} else if (array instanceof byte[]) {
return Arrays.toString((byte[]) array);
} else if (array instanceof char[]) {
return Arrays.toString((char[]) array);
} else if (array instanceof double[]) {
return Arrays.toString((double[]) array);
} else if (array instanceof float[]) {
return Arrays.toString((float[]) array);
} else if (array instanceof int[]) {
return Arrays.toString((int[]) array);
} else if (array instanceof long[]) {
return Arrays.toString((long[]) array);
} else if (array instanceof short[]) {
return Arrays.toString((short[]) array);
}
throw new IllegalArgumentException("Array has incompatible type: " + array.getClass());
}
public interface Closure<E> {
void execute(int index, E item);
}
}
View on GitHub (pinned to 7b4caf9e54)
Solutions
- Use String.valueOf(obj) or obj.toString() for non-array objects.
- Convert collections to arrays: ArrayUtils.toString(list.toArray()).
- Add an isArray() guard and branch to a non-array path.
- Prefer Arrays.toString / Arrays.deepToString directly when you already have a typed array.
Example fix
// before
String s = ArrayUtils.toString("hello"); // Array has incompatible type: class String
// after
String s = (obj == null) ? "null" : obj.toString(); Defensive patterns
Strategy: type-guard
Validate before calling
String s = (array == null)
? "null"
: (array.getClass().isArray() ? ArrayUtils.toString(array) : String.valueOf(array)); Type guard
static boolean isArray(Object o) {
return o != null && o.getClass().isArray();
} Try / catch
try {
s = ArrayUtils.toString(obj);
} catch (IllegalArgumentException e) {
s = String.valueOf(obj);
} Prevention
- ArrayUtils.toString is array-only; use String.valueOf for scalars.
- Convert collections to arrays before calling toString.
- Branch on getClass().isArray() for polymorphic inputs.
When it happens
Trigger: Calling toString on a scalar Object (String, Integer, custom POJO) or a Collection instead of an array. The method is array-specific; it is not a general Object.toString replacement.
Common situations: Using ArrayUtils.toString as a generic debug printer for arbitrary objects; passing a List instead of list.toArray(); feeding boxed primitives from deserialized JSON.
Related errors
- Not an array: {}
- Index: {}, array1 Length: {}
- Index: {}, Length: 0
- Index: {}, Length: {}
- Unsupported object type: {}
AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14).
Data as JSON: /api/errors/00dd0c2d611cec83.
Report an issue: GitHub.