Why am i getting "outofmemoryerror" in java?

Example:

This error indicates the JVM ran out of memory. This can be due to creating too many objects or large data structures.

Solution:

Optimize your code, or consider increasing the JVM's memory allocation using '-Xmx'.

Beginner's Guide to Java