1. Home
  2. Windows

How to fix “Could not create the Java virtual machine”

Java remains a popular programming language to this day. It may be old but it hasn’t lost its user-base nor its usefulness over the years. Many developers continue to use it and it is in active development. Changes and improvements to the language are made all the time that make compiling and running Java-based apps incredibly easy.

Java virtual machine error

Fix Could not create the Java virtual machine

The “Could not create the Java virtual machine” error normally appears when compiling code in an IDE. The error isn’t descriptive enough to point users to the exact problem however, it is normally a result of;

  • Incorrect Java version being used
  • Incorrect SDK version installed
  • Incorrect environment variables set up
  • Syntax errors when declaring the version of Java that is to be used
  • Missing libraries in the IDE
  • Errors in memory management

The solution will vary depending on the underlying cause. Try the following.

1. Check compatible Java version

The Could not create the Java virtual machine normally appears when code is compiled in an IDE. This happens because the IDE is not compatible with the version of Java that is installed on your system. 

Check which versions of Java your IDE supports. Next, check which version of Java is installed, and make sure it is consistent with the supported version. If it isn’t, install the correct version.

2. Check Environment variables

The Java parameters that are set in the Environment variables on Windows 10 can cause the Could not create the Java virtual machine error. 

  1. Open File Explorer.
  2. Paste this explorer shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE} in the location bar and tap Enter.
  3. Click Advanced System Settings in the panel on the left.
  4. Go to the Advanced tab.
  5. Select Environment Variables and click New under System Variables.
  6. Enter _JAVA_OPTIONS in the name field.
  7. In the path/value, enter: -Xmx1024M
  8. Click OK.
  9. Restart the app.

Additionally, you should make sure that the correct path for the Java SDK is given.

  1. Open File Explorer and go to C:\Program Files\Java
  2. Open the folder for the JDK version you want to use.
  3. Copy the path to the folder.
  4. Open Environment variables (see previous steps).
  5. Under System variables, select JAVA_HOME.
  6. Click Edit.
  7. Enter the path that you copied and click OK.

3. Check startup arguments

Check the startup arguments that have been set. You may have the correct version of Java installed but the startup arguments may have set the version that is to be used for compiling to something else. If you’ve performed and in-place upgrade of Java, it is highly likely the startup arguments are still referencing the older version.

4. Check syntax

For any arguments that you’re entering, make sure the syntax is correct. The slightest mistake can result in the Could not create the Java virtual machine error. Look for an extra hyphen or incorrect version that has been declared. 

5. Reinstall Java

Try reinstalling Java. It may solve problems that you’re having when opening an IDE or similar app.

  1. Open Control Panel.
  2. Go to Programs>Uninstall a program.
  3. Look for Java and select it.
  4. Click the Uninstall button at the top.
  5. Allow Java to uninstall.
  6. Download and install Java again from here.

6. Check memory allocation

One of the main reasons the Could not create the Java virtual machine error appears is if there is insufficient memory allocated for use.

  1. Open File Explorer. 
  2. Go to C:\Program Files\Java
  3. Open the JDK folder with the currently installed version number.
  4. Look for a file called jvisualvm.exe and run it.
  5. The app will provide a GUI for managing memory.
  6. Increase the amount of memory and try again.

Conclusion

Setting up a development environment can often take a lot of time. There are many components that must be set up and requirements that must be met before you can develop or compile code. These errors aren’t unique to Java as all languages have their own set of requirements that must be met in order to use them. 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.