Unable to run Java code with Intellij IDEA

后端 未结 12 2393
说谎
说谎 2020-12-14 05:18

I have just downloaded the IDE, and I want to edit my first Java file with it, I\'m not interested in creating a whole project, just editing the single file.

So I op

相关标签:
12条回答
  • 2020-12-14 05:59

    Last resort option when nothing else seems to work: close and reopen IntelliJ.

    My issue was with reverting a Git commit, which happened to change the Java SDK configured for the Project to a no longer installed version of the JDK. But fixing that back still didn't allow me to run the program. Restarting IntelliJ fixed this

    0 讨论(0)
  • 2020-12-14 06:01

    -First Move Your Code Files in side the "src" Folder

    -Make sure your Main method is declared like the following

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

    then:

    • Go to Project configurations
    • select Java application,
    • check allow parallel run
    • and select your main class

    and it should work

    0 讨论(0)
  • 2020-12-14 06:03

    I had the similar issue and solved it by doing the below step.

    1. Go to "Run" menu and "Edit configuration"
    2. Click on add(+) icon and select Application from the list.
    3. In configuration name your Main class: name of your main class.
    4. Working Directory : It should point till the src folder of your project. C:\Users\name\Work\ProjectName\src

      This is where I had issue and after correcting this, I could see the run option for that class.

    0 讨论(0)
  • 2020-12-14 06:07

    Something else that worked for me:

    1. Right click the folder in src containing your main
    2. You'll see an option "run 'file.main()'" with the run icon.
    3. Click it, and then the run icon in the top right and bottom left will turn green from then on.
    0 讨论(0)
  • 2020-12-14 06:11

    right click on the "SRC folder", select "Mark directory as:, select "Resource Root".

    Then Edit the run configuration. select Run, run, edit configuration, with the plus button add an application configuration, give it a name (could be any name), and in the main class write down the full name of the main java class for example, com.example.java.MaxValues.

    you might also need to check file, project structure, project settings-project, give it a folder for the compiler output, preferably a separate folder, under the java folder,

    0 讨论(0)
  • 2020-12-14 06:11

    If you are just opened a new java project then create a new folder src/ in the man project location.

    Then cut and paste all your package in that folder.

    Then Right click on src directory and select option Mark Directory As > Sources Root.

    0 讨论(0)
提交回复
热议问题