Error could not create the Java virtual machine in java

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.
For example:
Let’s say you want to specify maximum heap size as 1024 MB then you can put VM argument as -Xmx1024M.

MemorySymbol
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,
    java -Xmx4096M MyApplication
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Could not create the Java virtual machine.
  • You might have put space between -Xmx and 4096M. For example,
    java -Xmx 4096M MyApplication
    Invalid maximum heap size: -Xmx
    Error: 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,
    java -Xmx1024 m MyApplication
    Error occurred during initialization of VM
    Too 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,
    java -Xms1024M -Xmsx512M MyApplication
    Error occurred during initialization of VM
    Initial heap size set to a larger value than the maximum heap size

    Here is the solution for Initial heap size set to a larger value than the maximum heap size

  • You have put -Xms1024MB -Xmx2048MB instead of -Xms1024M -Xmx2048M. For example,
    java -Xms1024MB -Xmx2048MB MyApplication
    Invalid initial heap size: -Xms1024MB
    Error: 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.

That’s all about error could not create the Java virtual machine in java.

Was this post helpful?

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *