NegativeArraySizeException in Java — What It Means and How to Fix It
What Java's NegativeArraySizeException means and how to fix it.
Published November 3, 2026
NegativeArraySizeException is thrown when code attempts to create an array with a negative size.
Key points
- Read the full stack trace from the top — it names the exact class, method, and line where the exception originated
Example
int[] a = new int[-1]; // NegativeArraySizeException