In this post, we will about an error: Could not create the Java virtual machine in java.
You can provide VM arguments to provide heap size for Java virtual machine.You can specify VM argument -Xms and -Xmx in form of KB,MB or GB.
Let’s say you want to specify maximum heap size as 1024 MB then you can put VM argument as -Xmx1024M.
|Kilobytes (KB)||k or K|
|Megabytes (MB)||m or M|
|Gigabytes (GB)||g or G|
There can be many reasons for this error. I will try to list down the most obvious reason for this error.
You might be getting this error because of one of below reasons.
- Heap size is larger than your computer’s physical memory. For example,
123456java -Xmx4096M MyApplicationError occurred during initialization of VMCould not reserve enough space for object heapCould not create the Java virtual machine.
- You might have put space between -Xmx and 4096M. For example,
123456java -Xmx 4096M MyApplicationInvalid maximum heap size: -XmxError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.
- You might have put space between -Xmx1024 and m. For example,
12345java -Xmx1024 m MyApplicationError occurred during initialization of VMToo small maximum heap
If you do not provide anything after 1024, it takes by default memory into bytes.
- -Xms might be higher than -Xmx. For example,
12345java -Xms1024M -Xmsx512M MyApplicationError occurred during initialization of VMInitial heap size set to a larger value than the maximum heap size
- You have put -Xms1024MB -Xmx2048MB instead of -Xms1024M -Xmx2048M . For example,
123456java -Xms1024MB -Xmx2048MB MyApplicationInvalid initial heap size: -Xms1024MBError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.
You can check what kind of error you are getting and fix it with above solutions.Please comment if you find some other reason for this error.
Join Our News Letter – Stay Updated
Subscribe to Awesome Java Content.