88

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.

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

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

Matt
  • 9,068
  • 12
  • 64
  • 84
Warda
  • 1,226
  • 2
  • 11
  • 17

6 Answers6

124

This is because the className value 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)

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:

enter image description here

Elham Kohestani
  • 3,013
  • 3
  • 20
  • 29
  • ok... module not specified what was that? I'm learning from this [tutorials of node.js](https://www.youtube.com/watch?v=-u-j7uqU7sI) – Warda Jun 24 '16 at 17:57
  • I provided an update check it I hope it may help you – Elham Kohestani Jun 24 '16 at 18:27
  • Somehow I'm making mistakes... Thanks a ton!! :) – Warda Jun 24 '16 at 18:54
  • 7
    In the module classpath, I don't get the option... why? – Warda Jun 24 '16 at 19:37
  • 1
    That maybe because of renaming the project, but I am not sure. Have you renamed your project? – Elham Kohestani Jun 25 '16 at 07:08
  • The blunder I was doing i.e: I hadn't installed the plugins. If anyone uses IntelliJ IDEA ultimate, you've to installed plugins otherwise download Webstorm. Webstorm doesn't need plugins. [Tutorials](https://www.youtube.com/watch?v=-u-j7uqU7sI&list=PL6gx4Cwl9DGBMdkKFn3HasZnnAqVjzHn_&index=1) for easy way to understand Node.js. :) – Warda Jun 30 '16 at 17:14
  • Thanks a ton Elham... :) – Warda Jun 30 '16 at 17:15
  • You are welcome. I hadn't known that you have not installed the plugin anyway good to know that you have found the solution.:) – Elham Kohestani Jun 30 '16 at 17:28
21

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

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

Hanz
  • 244
  • 3
  • 8
  • I don't have a pom.xml file in my project, is there a way to generate it? – jacob12 Aug 13 '23 at 08:13
  • you may can add it by yourself,read this maven introduction know more about maven https://maven.apache.org/what-is-maven.html. send me email if you still dont understand : hanz27124@gmail.com – Hanz Aug 31 '23 at 05:53
2

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

  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.

enter image description here

tonderaimuchada
  • 215
  • 2
  • 6
1

I faced the exact issue of module not found and solved it by navigating to pom.xml file in file system of my project and opening it as a maven project in my intelliJIdea.

Then it has populated the sub modules for selection in the edit configurations window.

Ravi
  • 11
  • 1
0

Faced the same issue. To solve it,

Gomez NL
  • 912
  • 9
  • 12
0

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

He was using jdk 12.0.2 .

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

  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.
Onat Korucu
  • 992
  • 11
  • 13