Java IntelliJ IDEA“所选目录不是JDK的有效主目录”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21713414/
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 10:13:39  来源:igfitidea点击:

IntelliJ IDEA "The selected directory is not a valid home for JDK"

javawindowsintellij-idea

提问by Maurdekye

I just installed IntelliJ IDEA and I'm trying to set it up. I've gotten to the part where I need to select my home directory for my JDK.

我刚刚安装了 IntelliJ IDEA,我正在尝试设置它。我已经到了需要为我的 JDK 选择主目录的部分。

I tried navigating to my Java installation, C:\Program Files (x86)\Java, and clicked okay but it told me the message above. So, I tried C:\Program Files (x86)\Java\jre7and that didn't work either.

我尝试导航到我的 Java 安装,C:\Program Files (x86)\Java然后单击 OK,但它告诉我上面的消息。所以,我试过了C:\Program Files (x86)\Java\jre7,也没有奏效。

I tried reinstalling the latest JDK (from here) and I still couldn't choose my JDK. I even dragged the .jarinstaller I got from the website and the file selector window wouldn't recognize it.

我尝试重新安装最新的 JDK(从这里),但仍然无法选择我的 JDK。我什至拖动.jar了从网站上获得的安装程序,但文件选择器窗口无法识别它。

I'm at a standstill and I don't know what to do.

我处于停滞状态,我不知道该怎么办。

采纳答案by Branislav Lazic

Because you are choosing jredir. and not JDKdir. JDKdir. is for instance (depending on update and whether it's 64 bit or 32 bit): C:\Program Files (x86)\Java\jdk1.7.0_45In my case it's 32 bit JDK 1.7update 45

因为你选择了jredir。而不是JDK目录。JDK目录 例如(取决于更新以及它是 64 位还是 32 位):C:\Program Files (x86)\Java\jdk1.7.0_45就我而言,它是 32 位JDK 1.7更新 45

回答by Suelen D.

I had the same issue. But I figured it out by choosing this path:

我遇到过同样的问题。但我通过选择这条路径想通了:

First at all, you need to select the C:\folder. Then, you select Program Files. After it, you select java, and finally the jdkyou downloaded. In my case, I downloaded the JDK1.8.0_60 version.

首先,您需要选择C:\文件夹。然后,您选择Program Files。之后,您选择java,最后选择您下载的jdk。就我而言,我下载了 JDK1.8.0_60 版本。

To resume the path:

要恢复路径:

C:\Program Files\java\jdk1.8.0_60

After you are done with it, you can click on the button next. Then you select the create project from templates. This will create a java application with a main() method. After it, you click next to create the name of you project.

完成后,您可以单击下一步按钮。然后您从模板中选择创建项目。这将创建一个带有 main() 方法的 Java 应用程序。之后,单击下一步以创建项目的名称。

I hope this helps you.

我希望这可以帮助你。

回答by Sarah Phillips

It got this error because I had managed to clobber jdk1.8.0_60 with the jre!

之所以出现此错误,是因为我已设法使用 jre 破坏了 jdk1.8.0_60!

回答by Koushal Deva

This error occurs because if you choosing the path deep in JDK or JRE. The exact path that should be chosen is in my case 64 bit

发生此错误的原因是,如果您选择了 JDK 或 JRE 中的深层路径。应该选择的确切路径在我的情况下是 64 位

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

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

if 32 bit

如果是 32 位

C:\Program Files (86)\Java\jdk1.8.0_91

C:\Program Files (86)\Java\jdk1.8.0_91

回答by killlinuxkill

May be your jdk is in /usr/lib/jvm/. This variant for linux.

可能是你的 jdk 在 /usr/lib/jvm/ 中。此变体适用于 linux。

回答by A-Sharabiani

One thing we should note: the jdkshould be installed on C:drive.

我们应该注意的一件事:jdk应该安装在C:驱动器上。

I had JDK installed on my D:drive like this:

我的D:驱动器上安装了 JDK,如下所示:

D:\Program Files\Java\jdk1.8.0_101

And it would still give me the same error. For some reason Java should be installed on C: drive.

它仍然会给我同样的错误。出于某种原因,Java 应该安装在 C: 驱动器上。

回答by Nguyen Minh Hien

In case you missed the configuration at the Project Structure(File -> Project Structure), just reconfigure it like below:

如果您错过了项目结构中的配置(文件 -> 项目结构),只需重新配置如下:

For Java enter image description here

对于 Java 在此处输入图片说明

For Android enter image description here

安卓版 在此处输入图片说明

Enjoy coding J

享受编码 J

回答by Paulo Merson

For Windows, apparently the JDK has to be under C:\Program Files.

对于 Windows,显然 JDK 必须在C:\Program Files 下

This does not work:

这并不起作用

C:\dev\Java\jdk1.8.0_191     

This works:

有效

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

(I'm using IntelliJ IDEA Ultimate 2018.2.4.)

(我使用的是 IntelliJ IDEA Ultimate 2018.2.4。)

回答by Mohammed Fathi

for me ,with JDK11 and IntelliJ 2016.3 , I kept getting the same message so I decided to uninstall JDK11 and installed JDK8 instead and it immediately worked!

对我来说,使用 JDK11 和 IntelliJ 2016.3,我一直收到相同的消息,所以我决定卸载 JDK11 并安装 JDK8,它立即起作用了!

回答by nwhaught

I ended up needing to replace 2017 with 2019, and everything worked fine. /shrug... no other suggestions here worked for me.

我最终需要用 2019 替换 2017,并且一切正常。/耸肩...这里没有其他建议对我有用。