Search code examples
javaintellij-idearun-configurationmain-method

Intellij Idea - can't run a simple java class even though the main method is declared


I'm a self-taught coder who is new to both Java & Intellij Idea. I wanted to run a simple Java class called payroll in Intellij Idea Ultimate 2017.3

public class payroll {
  public static void main(String[] args) {
    int hours = 50;
    double grossPay, payRate = 25.0;

    grossPay = hours * payRate;
    System.out.println("your gross pay is $" + grossPay);}
  }

Unfortunately IDEA detects some errors indicating that it can't resolve symbols "String" and "System". And when I tried Run/Edit Configuration, the IDE stated that the main method isn't found in the class, but obviously it is declared already

I've used Eclipse & Netbeans before and things just went smoothly then. Can anyone please point out the main cause of this nuisance for me and how to work it out?

Here is the screenshot of the program


Solution

  • If core Java lang (java.lang.*) classes cannot be resolved you may need to define the JDK you want to use with IDEA. Here is a link to how to define the JDK (Java Development Kit) you want to use for your project(s): LINK.

    You may also need to confirm the JDK path is correct by navigating to the folder and ensuring the JDK version you are using is indeed located there.

    Hope this helps!