Java 错误:未指定模块(IntelliJ IDEA)

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

Error: Module not specified (IntelliJ IDEA)

javaintellij-ideasettings

提问by warda hamk

I was trying to execute a simple program in IntelliJ IDEA as a static web project. I'm newbie and I'm learning web development with Node.js. I took help from the official website of IntelliJ IDEA, but the error was same. Though, I configured the settings and Project structure also.

我试图在 IntelliJ IDEA 中作为静态 Web 项目执行一个简单的程序。我是新手,正在学习使用 Node.js 进行 Web 开发。我从 IntelliJ IDEA 的官方网站获取帮助,但错误是相同的。不过,我也配置了设置和项目结构。

Error:

错误:

"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 2016.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2016.1.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain ""
Exception in thread "main" java.lang.ClassNotFoundException: 
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)

Process finished with exit code 1

Snapshot of IDE

IDE 快照

Please help me to sort out this problem. I'm digging out this problem since few days.

请帮我解决这个问题。几天以来,我一直在挖掘这个问题。

采纳答案by Elham Kohestani

This is because the classNamevalue which you are passing as argument for
forName(String className)method is not found or doesn't exists, or you a re passing the wrong value as the class name. Here is also a link which could help you.

1.https://docs.oracle.com/javase/7/docs/api/java/lang/ClassNotFoundException.html
2.https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#forName(java.lang.String)

这是因为className您作为
forName(String className)方法参数传递的值未找到或不存在,或者您将错误的值作为类名传递。这里还有一个可以帮助您的链接。

1. https://docs.oracle.com/javase/7/docs/api/java/lang/ClassNotFoundException.html
2. https://docs.oracle.com/javase/7/docs/api/java/lang /Class.html#forName(java.lang.String)

Update

更新

Module not specified

According to the snapshot you have provided this problem is because you have not determined the app module of your project, so I suggest you to choose the app module from configuration. For example:

根据你提供的快照,这个问题是因为你还没有确定你项目的app模块,所以建议你从配置中选择app模块。例如:

enter image description here

在此处输入图片说明

回答by Hanz

this is how I fix this issue
1.open my project structure

这就是我解决这个问题的方法 1.
打开我的项目结构

2.click module enter image description here3.click plus button enter image description here4.click import module,and find the module's pom enter image description here5.make sure you select the module you want to import,then next next finish:) enter image description here

2.点击模块 3.点击 在此处输入图片说明加号 在此处输入图片说明4.点击导入模块,找到模块的pom 在此处输入图片说明5.确定你选择了要导入的模块,然后next next完成:) 在此处输入图片说明

回答by Gomez NL

Faced the same issue. To solve it,

面临同样的问题。要解决它,

  • 我必须使用命令行下载并安装最新版本的 gradle$ sdk install gradle使用包管理器或$ brew install gradlemac。如果还没有,您可能需要先安装 brew
  • 然后我清理了项目并重新启动了 android studio,它工作了。

回答by Onat Korucu

This happened to me when I started to work with a colleque's project.

当我开始与 colleque 的项目合作时,这发生在我身上。

He was using jdk 12.0.2 .

他使用的是 jdk 12.0.2 。

If you are suspicious jdk difference might be the case (Your IDE complains about SDK, JDK etc.):

如果您怀疑 jdk 可能存在差异(您的 IDE 抱怨 SDK、JDK 等):

  1. Download the appropriate jdk
  2. Move new jdk to the folder of your choice. (I use C:\Program Files\Java)
  3. On Intellij, click to the dropdown on top middle bar. Click Edit Configurations. Change jdk.
  4. File -> Invalidate Caches and Restart.
  1. 下载合适的jdk
  2. 将新 jdk 移动到您选择的文件夹。(我使用 C:\Program Files\Java)
  3. 在 Intellij 上,单击顶部中间栏的下拉菜单。单击编辑配置。换jdk。
  4. 文件 -> 使缓存无效并重新启动。

回答by tonderaimuchada

For IntelliJ IDEA 2019.3.4 (Ultimate Edition), the following worked for me:

对于 IntelliJ IDEA 2019.3.4(终极版),以下对我有用:

  1. Find the Environment variables for your project.
  2. Specify, from the dropdowns, the values of "Use class path of module:" and "JRE" as in the attached screenshot.
  1. 查找项目的环境变量。
  2. 从下拉列表中指定“使用模块的类路径:”和“JRE”的值,如所附屏幕截图所示。

enter image description here

在此处输入图片说明