简体   繁体   中英

Java compile error in Visual Studio Code: Could not find or load main class

I mistakenly executed those two lines on console:

rm -rf ~/Library/Application\ Support/Code/Cache/*

rm -rf ~/Library/Application\ Support/Code/CachedData/*

I hoped to clear cache to improve speed, but then I discovered that it deletes some key files and I failed debug my java file every time after then which said:

bash-3.2$ /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java --enable-preview -Dfile.encoding=UTF-8 -cp /private/var/folders/58/tqd41r6x5rlfzms1y1rx7s_m0000gn/T/vscodesws_cb741/jdt_ws/jdt.ls-java-project/bin Test Error: Could not find or load main class Test Caused by: java.lang.ClassNotFoundException: Test

Could not find or load main class? But in the file the main class is right declared and I successfully ran before the problem occurred.

Thank you very much!

I figured out at last. Just open a folder and you can do for free. Also, don't change setting.json. After I reinstalled macOS...(Yes, there's no mistake here) I got a right setting.json and here's its code:

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.errors.incompleteClasspath.severity": "ignore",
    "files.autoSave": "afterDelay",
    "java.configuration.checkProjectSettingsExclusions": false,
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "terminal.integrated.lineHeight": 0,
    "python.jediEnabled": false
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM