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

我刚刚安装了 IntelliJ IDEA 我正在尝试建立它。我已经到了需要为 JDK 选择主目录的地步。

我试着导航到我的 Java 安装 C:\Program Files (x86)\Java,然后点击 OK,但是它告诉了我上面的信息。所以,我试了 C:\Program Files (x86)\Java\jre7,但也没有成功。

我尝试重新安装最新的 JDK (来自 给你) ,但仍然无法选择我的 JDK。我甚至拖动我从网站和文件选择器窗口得到的 .jar安装程序不会认出它。

我停滞不前,不知道该怎么办。

179512 次浏览

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

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 jdk you downloaded. In my case, I downloaded the JDK1.8.0_60 version.

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.

I hope this helps you.

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

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

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

if 32 bit

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

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

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

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

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.

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

For Java enter image description here

For Android enter image description here

Enjoy coding J

For Windows, apparently the JDK has to be under 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.)

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!

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

I had \bin as part of the path. Up one level of the selected directory worked for me.

I had the same problem. The solution was to update IntelliJ to the newest version.

For anyone on a Mac with a homebrew-installed openjdk, you need to use the directory under libexec: <openjdk11_directory>/libexec/openjdk.jdk/Contents/Home.

Thanks to https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007751379/comments/360001513560.

Although JDK version 8 can be added into IntelliJ IDEA version 2017.2.6, I couldn't add JDK version 11.0.14 into and got the same error. Because of this, I downloaded new version of IntelliJ IDEA version (2021.3.2) and I could add JDK 11.0.14 into IntelliJ easily without any error. Using newer release of IntelliJ than JDK release can be reasonable recommendation for people who meet this kind of problems.

upgrade to recent version of intellij work for me