(Java)正确安装Java后,基于Java的程序或游戏永远可靠。但最近用户报告说,他们在尝试运行Minecraft等(Minecraft)Java程序时无法创建 Java 虚拟机。这意味着Java程序用来运行的虚拟机没有正确安装。如果您也在处理同样的问题,那么您来对地方了。我们为您带来了一个完美的指南,可以帮助您修复错误:无法创建 java 虚拟机。
如何修复无法在 Windows 10 中创建 Java 虚拟机(How to Fix Could Not Create the Java Virtual Machine in Windows 10)
在集成开发环境(Integrated Development Environment)(IDE)中编译代码时经常出现错误:无法构建Java虚拟机。(Java)它通常是由
-
用于打开 Java 的参数或选项不正确:(Incorrect arguments or options used to open Java:)如果您运行自己的应用程序或开源应用程序,则可能会出现此错误,并可能导致系统不稳定。
-
Java 最大堆内存不足:(Insufficient Java maximum heap memory: )执行最大堆大小大于系统变量(System Variable)中设置的应用程序可能会导致此错误。
-
Java 可执行文件或在没有管理权限的(Java executable or programme running without Administrative privileges: )情况下运行的程序:运行需要管理员访问权限才能正常工作的应用程序时,可能会发生此错误。
我们现在了解了此错误背后的原因。Java用户还遇到了其他类似的错误,例如Java虚拟机启动器错误,这主要是由于Java安装问题而发生的。让我们从修复无法创建java虚拟机错误的方法开始。
初步检查(Preliminary Checks)
-
检查启动参数:(Check startup arguments: )检查您指定的启动参数。即使在正确的Java版本中,启动设置也可以修改用于编译的版本。如果您已经进行了就地Java更新,则启动参数很可能仍引用早期版本。
-
检查语法:(Check syntax: )确保(Make)您的参数语法正确。即使是微不足道的错误也会提示无法创建Java虚拟机错误。检查额外的连字符或记录不正确的版本。
-
检查 JDK 损坏:(Check JDK Corruption: )损坏的Java 开发工具包(Java Development Kit)可能导致错误:无法创建 Java 虚拟机。您可以按照以下步骤检查它是否已损坏:
1. 按Windows 键(Windows key),键入命令提示符(Command Prompt)并单击以管理员身份运行(Run as administrator)。
2 键入c:\> java -version并按Enter 键。(Enter key.)
3.如果执行命令报错,重新安装JDK(reinstall JDK)。检查重新安装JDK是否可以解决问题。如果没有,请尝试本文中列出的修复。
另请阅读:(Also Read:) 如何修复 javascript:void(0) 错误(How to Fix javascript:void(0) Error)
方法一:以管理员模式运行Java(Method 1: Run Java in Administrator Mode)
(Apps)不需要管理员访问权限的(Admin)应用程序在Windows PC上可能会变得不稳定,并可能导致包括错误在内的问题:无法创建 java 虚拟机。可以通过强制主要Java可执行文件 (java.exe) 以管理权限运行来修复它。请按照以下步骤执行此操作。
1. 按Windows + E keys打开文件资源管理器(File Explorer)。
2.在文件资源管理器(File Explorer)中导航到Java.exe。它一般在
C:\Program Files\Java\*JRE build version*\bin
其中JRE构建版本因安装的版本而异。
或者
C:\Program Files(x86)\Common Files\Oracle\Java\javapath
注意:(Note:)如果您将Java安装在其他位置,请按照该路径并找到Java.exe。
3. 右键单击 Java.exe并选择属性(Properties )以打开属性窗口。
4. 转到兼容性(Compatibility)选项卡,选中标记为以管理员身份运行此软件(Run this software as an administrator)的框,如图所示。
5. 单击应用(Apply )和确定( OK )以保存更改。
现在,无论何时打开 Java,它都会以管理员权限运行。
方法 2:增加 Java 堆大小(Method 2: Increase Java Heap Size)
当Java(Java)系统内存不足需要打开虚拟机(Virtual Machine)客户端时,可能会发生此错误。Java默认配置为使用最大堆大小并运行超过堆大小限制的应用程序,将发生错误。创建新的系统变量(System Variable)以增加可用内存可能会解决此问题,您可以按照以下步骤操作
1. 同时按下Windows + R 键(keys)打开运行(Run)对话框。
2. 键入sysdm.cpl并按Enter 键(Enter key )打开系统属性(System Properties)。
3. 转到高级(Advanced)选项卡。
4. 点击环境变量...按钮(Environment Variables… button),如图所示。
5. 在Environment Variables窗口中,单击System Variables下的(System Variables)New...按钮。
6.在New System Variable弹出窗口中将变量名称设置为_JAVA_OPTIONS并将变量值设置为–Xmx512M 。单击确定(OK)以保存更改。
注意:如果错误仍然存在,您可以通过将变量值设置为(Note:)–Xmx1024M而不是–Xmx512M来进一步增加内存,如步骤 6(Step 6)所示。
另请阅读:(Also Read:) 如何在浏览器中启用或禁用 JavaScript(How to Enable or Disable JavaScript in your Browser)
方法三:修改Java代码(Method 3: Modify Java Code)
一些用户报告说他们可以通过对其代码进行一些简单的更改来修复此错误。其中一些在下面提到。
1.在你的代码中用一个连字符替换双连字符(Replacing double hyphen – with a single hyphen – )可以解决这个问题。
sony@sony-VPCEH25EN:~$ java –version
Picked up JAVA_TOOL_OPTIONS: –javaagent:/usr/share/java/jayatanaag.jar
Unrecognized option: –version
sony@sony-VPCEH25EN:~$ java -version
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Unrecognized option: -version
2. 另外,考虑从你的论点中删除这个短语:(eliminating the phrase)
-Djava.endorsed.dirs=”C:\Program Files\Apache Software Foundation\Tomcat 8.5\endorsed”
3. 确保在 eclipse.ini 文件中的 vm args 上方添加 -vm 条目,( -vm entry is added above vm args in eclipse.ini file)否则将在 env wars 中选择JVM V6 。
注意:(Note:)如果你使用 Ubuntu,你必须知道它只支持Java 8。因此,您可以按照方法 3(Method 3 )所示卸载Java ,然后安装旧版本。
方法四:修改Eclipse.ini文件(Method 4: Modify Eclipse.ini File)
如果您使用的是Eclipse IDE,那么在 eclipse.ini 文件中进行一些更改可以修复错误代码无法创建 java 虚拟机(could not create the java virtual machine)。
注意:(Note:) Eclipse.ini位于安装Eclipse的目录中的Eclipse文件夹内。
第一步:减少内存使用(Step I: Decrease Memory Use)
1. 右键单击 Eclipse.ini文件并选择open with… > Notepad。
2. 寻找与-Xmx256m匹配的行。
注意:(Note:)也可以是 -Xmx1024m 或 -Xmx 512m。
3. 将默认值更改为与您的 PC RAM(RAM)更兼容的值,同时添加版本号。
例如,
-Xmx512m
-Dosgi.requiredJavaVersion=1.6
或者(OR)
-Xmx512m
-Dosgi.requiredJavaVersion=1.7
或者(OR)
-Xmx512m
-Dosgi.requiredJavaVersion=1.8
4. 尝试从 -launcher.XXMaxPermSize 行中删除 256m 值。(delete 256m value)
第二步:附加修改(Step II: Additional Modifications)
1. 如果可能,从文件中删除以下行。
-vm P:\Programs\jdk1.6\bin
2. 用下面给定的代码替换下面的行。
set -Dosgi.requiredJavaVersion=1.5
到
set -Dosgi.requiredJavaVersion=1.6.
3. 高分!行,尝试添加这一行:
-vm C:\Program Files (x86)\Java\jre6\bin\javaw.exe
4.通过以下行引用JVM.dll 。
-vm
C:\Program Files\Java\jre7\bin\client\jvm.dll
5.将(Replace)-vmargs替换为eclipse.ini文件中javaw.exe 的路径。
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-product
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256M
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
**-vm “c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe”**
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-Declipse.buildId=v21.1.0-569685
6. 将该行放在eclipse.ini文件的末尾并检查它是否有效。
-vmargs
-Xms40m
-Xmx512m
-XX:MaxPermSize=256m
7. 从eclipse.ini(eclipse.ini)中删除以下行并检查它是否解决了问题。
-XX:+UseStringDeduplication
-XX:+UseG1GC
注意:(Note:)如果问题仍然存在,请尝试擦除 eclipse.ini 文件,但请事先进行复制。此外,在启动Java(Java)之前关闭所有消耗大量内存的应用程序。
另请阅读:(Also Read:) 修复 Java 虚拟机或 JVM 未找到错误(Fix Java Virtual Machine or JVM not found error)
方法 5:重新安装 Java(Method 5: Reinstall Java)
在某些情况下,该问题是由于未正确安装Java或由于其安装已随时间损坏而引起的。因此,在完全删除Java后,我们将在此步骤中重新安装它。因此:
1. 同时按下Windows + R 键(keys)打开运行(Run)对话框。
2.输入Appwiz.cpl 并点击OK启动Programs and Features。
3.滚动(Scroll)浏览已安装的应用程序并找到Java。
4. 右键单击它并选择卸载(Uninstall )以卸载 Java。
注意:(Note:)您还应该卸载其他Java 开发(Java Development)工具包和更新。
5. 等待卸载过程完成并重新启动您的 PC(reboot your PC)。
6. 前往Java 下载页面(Java Downloads page)下载最新版本的Java 运行时环境(Java Runtime Environment)。
注意 1:(Note 1:)如果重新安装Java Runtime Environment不能解决问题,请下载最新版本的JDK。
注意 2:(Note 2:)如果您已经拥有JDK,请尝试使用不同的版本或删除它附带的Java Runtime Environment 。
常见问题 (FAQ)(Frequently Asked Questions (FAQs))
Q1。说不能构造Java虚拟机是什么意思?(Q1. What does it imply when it says could not construct Java Virtual Machine?)
Ans: Java 虚拟机(Java Virtual Machine)使用 -Xmx 选项来指定最大堆内存大小。eclipse.ini 文件中的-Xmx 选项( -Xmx option in eclipse.ini file)对于当前环境可能设置得太高,导致此错误消息。
Q2。什么是 Java 虚拟机?(Q2. What is the Java Virtual Machine?)
答:(Ans: )Java 虚拟机(Java Virtual Machine)( JVM ) 是一种程序,它允许计算机运行Java程序和其他已翻译成Java 字节码(Java Bytecode)的语言。JVM由正式描述 JVM 实现要求的标准来描述。(describes JVM implementation requirements.)
Q3。是否可以免费获得 Java?(Q3. Is it possible to get Java for free?)
Ans:要安装Java,您必须首先下载Oracle安装程序应用程序。从下拉菜单中选择免费 Java 下载。(Select Free Java Download)之后,您将被要求阅读并接受最终用户许可协议。
受到推崇的:(Recommended:)
我们希望本指南对您有所帮助,并且您能够解决无法创建 Java 虚拟机的(could not create the Java virtual machine)问题。让我们知道哪种方法最适合您。如果您有任何疑问或建议,请随时将它们放在评论部分。
Fix Could Not Create the Java Virtual Machine in Windows 10
Javа-based рrograms or games arе ever-reliable when Jaνa is рroperly installed. But recently users have reported that they could not create the javа virtual machine while attempting to run Javа programs like Minecraft. It means that the virtual machine used by Java programs tо function is not installed properly. If you are also dealing with the same problem, you are at the right plаce. We bring to you a perfect guide that will help you fix the error: could not create the java virtual machine.
How to Fix Could Not Create the Java Virtual Machine in Windows 10
The error: Could not construct the Java virtual machine is often appears when compiling code in Integrated Development Environment (IDE). It is usually caused by
-
Incorrect arguments or options used to open Java: If you run your own app or an open-source application this error may appear and can make system unstable.
-
Insufficient Java maximum heap memory: Executing an app that has more maximum heap size than what is set in System Variable may cause this error.
-
Java executable or programme running without Administrative privileges: This error may occur when running apps that require admin access to work appropriately.
We now understand the reasons behind this error. There are other similar errors experienced by Java users like Java virtual machine launcher error that mostly occurs due to Java installation issue. Let us begin with the methods to fix could not create the java virtual machine error.
Preliminary Checks
-
Check startup arguments: Examine the starting parameters you’ve specified. Even in correct Java version, startup settings can modify the version utilised for compilation. If you’ve done an in-place Java update, it is likely that startup parameters still refer to earlier version.
-
Check syntax: Make sure your arguments syntax is correct. Even meagre mistakes in it can prompt could not create the Java virtual machine error. Check for extra hyphens or versions that have been incorrecly recorded.
-
Check JDK Corruption: A corrupt Java Development Kit can cause error: could not create the java virtual machine. You can check whether it is corrupt or not by following these steps:
1. Hit the Windows key, type Command Prompt and click on Run as administrator.
2 Type c:\> java -version and hit the Enter key.
3. If executing the command gives an error, reinstall JDK. Check if reinstalling JDK resolves the issue. If not, try the fixed listed in this article.
Also Read: How to Fix javascript:void(0) Error
Method 1: Run Java in Administrator Mode
Apps without required Admin access can become unstable on Windows PC and may cause issues including error: could not create the java virtual machine. It can be fixed by forcing primary Java executable (java.exe) to run with administrative rights. Follow these steps to do so.
1. Press Windows + E keys to open File Explorer.
2. Navigate to Java.exe in File Explorer. It is generally in
C:\Program Files\Java\*JRE build version*\bin
where JRE build version varies depending on the installed version.
Or
C:\Program Files(x86)\Common Files\Oracle\Java\javapath
Note: If you installed Java in a different location, follow that path and locate Java.exe.
3. Right-click on Java.exe and select Properties to open Properties window.
4. Go to Compatibility tab, check the box marked Run this software as an administrator as shown.
5. Click Apply and OK to save changes.
Now whenever you open Java it will run with admin privileges.
Method 2: Increase Java Heap Size
This error can occur when Java is running out of system memory require to open Virtual Machine client. Java is configured by default to utilise maximum heap size and running an app that exceeds heap size limit, an error will occur. Creating a new System Variable to increase available memory might resolve this issue and you can do that by following these steps
1. Press Windows + R keys together to open the Run dialog box.
2. Type sysdm.cpl and press Enter key to open System Properties.
3. Go to the Advanced tab.
4. Click on Environment Variables… button as shown.
5. In Environment Variables window, click New… button under System Variables.
6. Set Variable name to _JAVA_OPTIONS and Variable value to –Xmx512M in New System Variable popup. Click OK to save changes.
Note: If the error persists, you can further increase memory by setting Variable value as –Xmx1024M instead of –Xmx512M as shown in Step 6.
Also Read: How to Enable or Disable JavaScript in your Browser
Method 3: Modify Java Code
Some users have reported that they can fix this error by making some simple changes in their code. Some of them are mentioned below.
1. Replacing double hyphen – with a single hyphen – in your code can fix this problem.
- The code with double hyphen
sony@sony-VPCEH25EN:~$ java –version
Picked up JAVA_TOOL_OPTIONS: –javaagent:/usr/share/java/jayatanaag.jar
Unrecognized option: –version
- The same code with a single hyphen
sony@sony-VPCEH25EN:~$ java -version
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Unrecognized option: -version
2. Also, consider eliminating the phrase from your argument:
-Djava.endorsed.dirs=”C:\Program Files\Apache Software Foundation\Tomcat 8.5\endorsed”
3. Make sure -vm entry is added above vm args in eclipse.ini file or else JVM V6 will be chosen in env wars.
Note: If you use Ubuntu, you must know it only supports Java 8. So, you can uninstall Java as shown in Method 3 and install an older version instead.
Method 4: Modify Eclipse.ini File
If you are using Eclipse IDE, then making some changes in eclipse.ini file can fix error code could not create the java virtual machine.
Note: Eclipse.ini is located inside Eclipse folder in the directory where you have installed Eclipse.
Step I: Decrease Memory Use
1. Right-click on Eclipse.ini file and select open with… > Notepad.
2. Look for a line matching -Xmx256m.
Note: It can also be -Xmx1024m or -Xmx 512m.
3. Change the default value to something more compatible with your PC RAM along with adding the version number.
For example,
-Xmx512m
-Dosgi.requiredJavaVersion=1.6
OR
-Xmx512m
-Dosgi.requiredJavaVersion=1.7
OR
-Xmx512m
-Dosgi.requiredJavaVersion=1.8
4. Try to delete 256m value from -launcher.XXMaxPermSize line.
Step II: Additional Modifications
1. Remove the following line from your file, if possible.
-vm P:\Programs\jdk1.6\bin
2. Replace the following line with the given code below.
set -Dosgi.requiredJavaVersion=1.5
To
set -Dosgi.requiredJavaVersion=1.6.
3. Above -marks! line, try adding this line:
-vm C:\Program Files (x86)\Java\jre6\bin\javaw.exe
4. Refer to JVM.dll by the following line.
-vm
C:\Program Files\Java\jre7\bin\client\jvm.dll
5. Replace -vmargs with the path of javaw.exe in eclipse.ini file.
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-product
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256M
-showsplash
com.android.ide.eclipse.adt.package.product
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
**-vm “c:\Program Files\Java\jdk1.7.0_07\bin\javaw.exe”**
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-Declipse.buildId=v21.1.0-569685
6. Place the line at end of eclipse.ini file and check if it works.
-vmargs
-Xms40m
-Xmx512m
-XX:MaxPermSize=256m
7. Delete the following lines from eclipse.ini and check if it solves the issue.
-XX:+UseStringDeduplication
-XX:+UseG1GC
Note: If the problem persists, try erasing the eclipse.ini file, but make a copy beforehand. Also, close all apps that consume high memory before launching Java.
Also Read: Fix Java Virtual Machine or JVM not found error
Method 5: Reinstall Java
In certain circumstances, the issue is caused by Java not being installed correctly or because its installation has been damaged over time. As a result, after entirely removing Java, we will reinstall it in this step. As a result:
1. Press Windows + R keys together to open the Run dialog box.
2. Type Appwiz.cpl and click OK to launch Programs and Features.
3. Scroll through installed applications and locate Java.
4. Right-click on it and select Uninstall to uninstall Java.
Note: You should also uninstall other Java Development kits and updates.
5. Wait for the uninstallation process to complete and reboot your PC.
6. Go to Java Downloads page to download the most recent version of Java Runtime Environment.
Note 1: If reinstalling Java Runtime Environment doesn’t fix the issue, download the most recent version of JDK.
Note 2: If you already had JDK, try using a different version or delete Java Runtime Environment that came with it.
Frequently Asked Questions (FAQs)
Q1. What does it imply when it says could not construct Java Virtual Machine?
Ans: The -Xmx option is used by Java Virtual Machine to specify maximum heap memory size. The -Xmx option in eclipse.ini file is probably set too high for the present environment which is causing this error message.
Q2. What is the Java Virtual Machine?
Ans: Java Virtual Machine (JVM) is a program that allows a computer to run Java programs and other languages that have been translated to Java Bytecode. JVM is described by a standard that formally describes JVM implementation requirements.
Q3. Is it possible to get Java for free?
Ans: To install Java, you must first download Oracle installer application. Select Free Java Download from drop-down menu. After that, you’ll be asked to read and accept end-user licensing agreement.
Recommended:
We hope that this guide was helpful and that you were able to fix could not create the Java virtual machine issue. Let us know which method worked for you the best. If you have any queries or suggestions then feel free to drop them in the comments section.