Search code examples
javacompiler-errorsidejavacspring-tool-suite

How to fix "Error: Can not find or load the main class"?


I'm trying to execute a simple java code.

the code worked fine using comand line : javac Go.java and java Go, but in Spring Tool Suite 3, the code did not work and I got the error below.

Note that I'm using jdk1.8.0_211

package com.test;

public class Go {

public static void main(String[] args) {
    System.out.println("test");
  }

}

I expect print test, but I get this error :

Error: Can not find or load the main class.

Solution

  • the cause of the problem is that I'm not the owner of the Laptop, it is managed by the administrator of the company where I work. I noticed that when I change the version of JAVA, the code runs correctly, but after restarting the Laptop, I get the same error again, so the cause was that every restart of the laptop, it updates java version, I fixed my PC to not updating java version again and it works