Compiler error – ‘error: cannot find or load main class com sun. tools. javac. Main’

I just started learning Java. I installed JDK on my computer, but now I'm trying Java's simple instead of compiling I installed JDK on C: / Java / JDK7 /

Whenever I try to compile, I get an error:

Error: Could not find or load main class com.sun.tools.javac.Main

This is how I compile:

javac test.java

I've also tried:

javac.exe test.java

I don't know if my code is wrong or anything, but here is my test java:

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

This is Java_ HOME:

C:\Java\jdk7\

Any help will be appreciated!

Solution

You may have manually installed JDK In any case, this error is almost certainly due to a defect in your Java installation To solve this problem, you must be in Java_ Execute the following command from the home / lib Directory:

This will unzip the tools that your installation (manually or not) did not complete for you Jar file Then try to execute:

This command should be very good. It is similar to the error that Java commands can use. Basically, it is for the same reason that your installation does not extract the necessary files You can refer to this link: JRE 1.7 returns: Java / Lang / NoClassDefFoundError: Java / Lang / object

I have this problem myself, and my solution is a little adaptation of this other answer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>