设置 JAVA_HOME 变量的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20204602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:15:54  来源:igfitidea点击:

Problems setting the JAVA_HOME variable

javaandroidandroid-studiojava-home

提问by anon

So I just downloaded Android Studio, and am trying to set the JAVA_HOME variable so I can run it. I'm using windows 8 and have followed all the instructions I've been able to find to no avail... went to advanced system settings > environment variables and then set the JAVA_HOME variable with the value containing my path to jre7. I've double checked the path a million times, I don't see anything wrong with it(C:\Program Files (x86)\Java\jre7). I know the variable name is right, and I know that windows is excepting the variable, I've even restarted twice. What am I doing wrong here? The only thing I can think of that may be wrong is the fact that I'm pointing to a jre instead of a jdk, but I've always thought that both worked... anyway, the exact error message I get when I try to open Android Studio says:

所以我刚刚下载了 Android Studio,并尝试设置 JAVA_HOME 变量以便我可以运行它。我正在使用 Windows 8 并遵循了我无法找到的所有说明...转到高级系统设置>环境变量,然后使用包含我的 jre7 路径的值设置 JAVA_HOME 变量。我已经仔细检查了路径一百万次,我没有发现它有任何问题(C:\Program Files (x86)\Java\jre7)。我知道变量名是正确的,我知道 Windows 不包括变量,我什至重新启动了两次。我在这里做错了什么?我唯一能想到的可能是错误的事实是我指向的是 jre 而不是 jdk,但我一直认为两者都有效......无论如何,我尝试时得到的确切错误消息打开 Android Studio 说:

No JVM installation found. Please install a 64-bit JDK. If you already have a JDK installed, define a JAVA_HOME variable in Computer > System Properties > System Settings > Environment Variables.

未找到 JVM 安装。请安装 64 位 JDK。如果您已经安装了 JDK,请在计算机 > 系统属性 > 系统设置 > 环境变量中定义一个 JAVA_HOME 变量。

If a jre doesn't work in place of a jdk, then how do I go about getting one? I know nothing about Java I just want to get into this IDE and play around with Android.

如果 jre 不能代替 jdk,那么我该如何获得一个?我对 Java 一无所知,我只想进入这个 IDE 并尝试使用 Android。

采纳答案by Adam S

No JVM installation found. Please install a 64-bit JDK.

未找到 JVM 安装。请安装 64 位 JDK。

It's asking for a 64-bit JDK. You say your environment variable is pointing at the following directory:

它要求 64 位 JDK。您说您的环境变量指向以下目录:

C:\Program Files (x86)\Java\jre7

C:\Program Files (x86)\Java\jre7

There's two things wrong here. First, you're pointing to a JRE - Java Runtime Environment. This is nota JDK- Java Development Kit. The JRE is for running Java applications; the JDK is for developingJava applications. There's a significant difference there.

这里有两件事不对。首先,您指向的是 JRE - Java 运行时环境。不是JDK- Java 开发工具包。JRE 用于运行 Java 应用程序;JDK 用于开发Java 应用程序。那里有显着差异。

Secondly, as others have mentioned, you're pointing the environment variable to the 32-bit version. You need a 64-bit JDK. This will be installed at C:\Program Files\Java\jdk1.7.0_XXor similar, by default.

其次,正如其他人所提到的,您将环境变量指向 32 位版本。您需要一个 64 位 JDK。C:\Program Files\Java\jdk1.7.0_XX默认情况下,这将安装在或类似的位置。

You can acquire a JDK installation from Oracle.

您可以从Oracle获取 JDK 安装。

回答by Brianjs

No JVM installation found. Please install a 64-bit JDK

This is looking for a 64bit version of the java JDK.

这是在寻找 64 位版本的 java JDK。

C:\Program Files (x86)is the x86 not 64bit.

C:\Program Files (x86)是 x86 不是 64 位。

Click the link below and make sure to download the x64 version.

单击下面的链接并确保下载 x64 版本。

Java SE Development Kit 7 Downloads

Java SE 开发工具包 7 下载

Then the folder path should be

那么文件夹路径应该是

C:\Program Files\Java\jre7

回答by Axel Kemper

By default, c:\Program Files (x86)(environment variable ProgramFiles(x86))is used for 32-bitinstallations. 64-bitinstallations use c:\Program Files(environment variable ProgramFiles).

默认情况下,c:\Program Files (x86)(环境变量ProgramFiles(x86))用于32-bit安装。64-bit安装使用c:\Program Files(环境变量ProgramFiles)。

When I open a cmdbox on my Windows 7 64-bit, I can issue the "set" command to get

当我打开一个cmd盒子时Windows 7 64-bit,我可以发出“ set”命令来获取

ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

This should be similar under Windows 8.

这在 Windows 8 下应该是类似的。

回答by Indu Devanath

Here is the official installation instructions - http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html

这是官方安装说明 - http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html

The important thing is

重要的是

  1. Set JAVA_HOMEto the location where jre or jdk is installed

  2. Add %JAVA_HOME%/binto your path variable.

  1. 设置JAVA_HOME为安装jre或jdk的位置

  2. 添加%JAVA_HOME%/bin到您的路径变量。

Make sure you add these to "System Variables" and not in "User variables for xxx"

确保将这些添加到“系统变量”而不是“xxx 的用户变量”

回答by MahNas92

Try runing Android Studio as administrator after setting the JAVA_HOME variable! It worked for me...

设置 JAVA_HOME 变量后,尝试以管理员身份运行 Android Studio!它对我有用...

回答by Equally Frustrated Stranger

Same thing happened to me and it turns out that all I had to do was unblock the file. Go to the file properties and at the bottom where it tells you it's from another computer and is blocked, just unblock it. This may not be true for everyone but it probably is if the path code is exactly what it should be and still isn't working.

同样的事情发生在我身上,结果我所要做的就是取消阻止文件。转到文件属性并在底部告诉您它来自另一台计算机并被阻止,只需取消阻止即可。这可能并不适用于每个人,但如果路径代码正是它应该的样子并且仍然无法正常工作,则可能是这样。

回答by Rashid Iqbal

the solution is simple,

解决办法很简单,

I think your java path contains /bin

我认为您的 java 路径包含/bin

C:\Program Files\Java\jdk1.8.0_181

C:\Program Files\Java\jdk1.8.0_181

just path to the folder of JDK

只是JDK文件夹的路径

like C:\Program Files\Java\jdk1.8.0_181

C:\Program Files\Java\jdk1.8.0_181

don't forget to restartyour IDE or Code Editor

不要忘记重新启动您的 IDE 或代码编辑器