Without the code or the full details of the Exception we can only guess.
But in general an OutOfMemoryError happens because (a) you have a ginormous amount of data in memory or (b) your code is stuck in a loop creating the same objects over and over again (more likely)
There are several JVM options that will increase the heap and stack size of the vm. Besides finding out what is eating all the memory, as James pointed out, you can look at garbage collection stats (java -verbose:gc, which will show, at least, how often the GC is running. You can increase your java heap size with -Xms and -Xmx, -XX:MaxPermSize. You can increase the java stack size with -Xss. Research these parameters before willy-nilly applying them, and go through your code to determine why you are running out of heap space. If you are using an IDE and running your program within the IDE, that's one reason you can quickly run out of memory.