0

I want to just compile and run a simple java file in IntelliJ, I already did these steps as others, who had this issues.

  1. Setup the Project Structure to have the correct Content Root for Modules.
  2. Setup the Run/Debug Configurations.

Here are the snapshots to my codes, my Project Structure and my Run/Debug Configurations enter image description here

enter image description here

enter image description here

Patrick
  • 797
  • 5
  • 15

2 Answers2

3

Look at the icon of the Names.java file. The icon has a letter J which is surronded by a red circle. This means your Java class is located outside of the source root. Refer to the links below to know more about the symbols used in intellij.

https://www.jetbrains.com/help/idea/symbols.html

To solve the above problem,you will have to configure the content root. Go to File > project structure > Modules and set the Lab1 folder as the src root.

After correctly setting it, the icon will be a blue circle surrounding the letter C.

More info about content root configuration is here: https://www.jetbrains.com/help/idea/configuring-content-roots.html

lambad
  • 1,046
  • 10
  • 21
0

Make sure you make your main class public.

public class Names {

    public static void main(String[] args) { }

}

that's what your class should look like.

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49