“Could Not Create the Java Virtual Machine”: How to Fix It

Laptop showing program code, where a Java app fails to start with a virtual machine error

Quick answer: “Error: Could not create the Java Virtual Machine” means Java refused to start because of one of its startup options, not because your program is broken. Look at the line just above the error: it names the bad option. Usually it’s a memory setting that’s too high or badly typed (such as -Xmx4G on 32-bit Java or -Xmx 2g with a space), an option your Java version doesn’t recognize, or a leftover _JAVA_OPTIONS environment variable. Fix or remove that option, and install 64-bit Java if you need more than about 1 GB of memory.

Applies to: Windows 11 and Windows 10, with Java 8, 11, 17, 21 or newer, and apps that run on Java such as Eclipse, Minecraft, Android Studio and Gradle.

Laptop showing program code, where a Java app fails to start with a virtual machine error

What the error means

Every Java program runs inside the Java Virtual Machine (JVM). Before it starts, the JVM reads its options from the command line, the app’s settings file and some environment variables. If any of those options is invalid, it stops straight away with:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Reinstalling the app rarely helps, because the bad option usually lives outside it. The fix is to find that option.

Step 1: Read the line above the error

Run the program from a Command Prompt so you can see the full message. For a plain Java program, you can test Java itself with:

java -version

If even that fails, the problem is in your system settings or Java install (Fix 1 or Fix 4). Otherwise, run the app’s own command or launcher and match the line above the error with this table:

Message above the errorCauseGo to
Picked up _JAVA_OPTIONS: ... or Picked up JAVA_TOOL_OPTIONS: ...An environment variable adds options to every Java programFix 1
Invalid maximum heap size or Invalid initial heap sizeThe -Xmx or -Xms value is typed wrongFix 2
Could not reserve enough space for object heapJava can’t get as much memory as you asked forFix 2 and Fix 4
Unrecognized option: ... or Unrecognized VM option ...An option is misspelled or not supported by this Java versionFix 3

Fix 1: Remove a bad _JAVA_OPTIONS variable

Some guides and installers tell you to set _JAVA_OPTIONS (or JAVA_TOOL_OPTIONS) so Java always gets more memory. Every Java program then picks it up, and one bad value breaks all of them. Check whether one is set:

echo %_JAVA_OPTIONS%
echo %JAVA_TOOL_OPTIONS%
echo %JDK_JAVA_OPTIONS%

If a line prints the variable name back unchanged (for example %_JAVA_OPTIONS%), it isn’t set. If it prints options, remove or correct it:

  1. Press Win, type environment variables and open Edit the system environment variables.
  2. Select Environment Variables.
  3. Look in both User variables and System variables for _JAVA_OPTIONS, JAVA_TOOL_OPTIONS or JDK_JAVA_OPTIONS.
  4. Select it and choose Delete, or Edit it to fix the value. Select OK on every window.
  5. Close and reopen Command Prompt (and the app) so it picks up the change.

If you really need a memory setting, put it in the app’s own settings instead (see the sections below), so it only affects that app.

Fix 2: Fix the memory setting (-Xmx)

Two RAM modules, the memory Java reserves with the Xmx setting

-Xmx sets the most memory Java may use, and -Xms sets how much it starts with. According to Oracle’s documentation, the value is a number followed by k, m or g, written straight after the option:

CorrectWrongWhy
-Xmx2g-Xmx 2gNo space allowed
-Xmx1024m-Xmx1024mb or -Xmx1024MBUse a single letter: k, m or g
-Xmx2g-Xmx2.5gWhole numbers only; use -Xmx2560m instead
-Xms512m -Xmx2g-Xms4g -Xmx2gThe starting size can’t be larger than the maximum

Also keep -Xmx well below your installed RAM, leaving room for Windows and other apps. To see how much you have, go to Settings > System > About and check Installed RAM. On an 8 GB PC, -Xmx4g is usually the most you’d want; most apps need far less.

If you get “Could not reserve enough space” even with a modest value like -Xmx2g, you’re probably running 32-bit Java, which can only use roughly 1 to 1.5 GB on Windows. See Fix 4.

Fix 3: Remove unrecognized or outdated options

Java options change between versions. Settings copied from an old guide or an old version of an app often include options newer Java no longer accepts. A common example is -XX:MaxPermSize (and -XX:PermSize), which belonged to Java 7 and earlier; current Java versions reject or ignore them. Delete those options; the nearest modern setting is -XX:MaxMetaspaceSize, but most people don’t need it at all.

Also check for simple typos: options are case-sensitive, start with a single hyphen (-Xmx, not --Xmx or —Xmx), and curly quotes or long dashes pasted from a web page or Word document will break them. Retype the option by hand if in doubt.

Fix 4: Use the right Java version (64-bit)

Run this in Command Prompt:

java -version
where java
  • The first line shows the version, for example openjdk version "21.0.4". Check what your app needs: newer apps often require Java 17 or 21, while some older ones only work on Java 8.
  • Look for 64-Bit in the last line. If it’s missing, you’re on 32-bit Java. Uninstall it in Settings > Apps > Installed apps and install a 64-bit build.
  • where java lists every java.exe Windows can find, in order. The first one is the one that runs. If an old version comes first, uninstall it or move the right one higher in the Path variable (same Environment Variables window as Fix 1).

Free, supported Java builds are available from Oracle, from Microsoft (the Microsoft Build of OpenJDK) and from Eclipse Adoptium. You can also install one with winget: run winget search OpenJDK and install the ID it lists. See how to use winget and update from the command line for more.

Laptop with code on screen, used to check which Java version is installed

Eclipse: “Failed to create the Java Virtual Machine”

Eclipse shows this in a small pop-up instead of a command-line message. The settings live in eclipse.ini, in the same folder as eclipse.exe. Make a copy of the file first, then open it in Notepad:

  1. Find the -Xmx and -Xms lines below -vmargs and lower them (for example -Xmx2048m), using the rules in Fix 2.
  2. Point Eclipse at a specific 64-bit Java by adding two lines above -vmargs: -vm on one line, and the full path to javaw.exe on the next.
  3. Keep each option on its own line, with no spaces at the end, and save the file.

A typical working block looks like this (your Java path will differ):

-vm
C:\Program Files\Java\jdk-21\bin\javaw.exe
-vmargs
-Xms256m
-Xmx2048m

The 64-bit version of Eclipse needs 64-bit Java, and the Eclipse release must support your Java version; recent releases need Java 17 or newer, so check the release notes for your version.

Other apps: where their Java settings live

  • Minecraft Launcher: Installations, hover over the installation, select the three dots, then Edit > More options. Fix the JVM arguments box; the -Xmx value there sets how much memory the game gets.
  • Android Studio and IntelliJ IDEA: Help > Edit Custom VM Options. If the IDE won’t start at all, the file is a .vmoptions file in your user configuration folder; remove the line you last changed.
  • Gradle builds: check org.gradle.jvmargs in gradle.properties, both in the project folder and in %USERPROFILE%\.gradle.
  • Batch files and shortcuts: open the .bat file or the shortcut’s Target box and correct the options after java.

If the app starts but then crashes with an access violation instead, see error 0xc0000005: the application was unable to start correctly. If several unrelated apps fail to start, check Windows system files with SFC and DISM.

Official sources: for more detail, see the official documentation:

Frequently asked questions

Should I run the app as administrator?

It rarely helps with this error. The JVM fails because of its options, not permissions. Fix the option named above the error instead.

How much memory should I give Java?

Only what the app needs. Many apps run fine with 1 to 2 GB; large IDEs or modded games may want 4 GB. Giving Java most of your RAM slows down everything else.

Why does every Java program fail, not just one?

That points to a system-wide setting, almost always a _JAVA_OPTIONS or JAVA_TOOL_OPTIONS variable (Fix 1), or a broken Java install first in your Path (Fix 4).

Do I need to uninstall old Java versions?

Not always, but old 32-bit or outdated versions often end up being the one that runs. Removing the ones you don’t need avoids surprises and closes old security holes.

How we write our guides: read our editorial policy.

Comments

Leave a Reply

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