添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Error: Could not find or load main class #1085

Closed
@TinghuiWang

Description

When running the Java program by clicking "Run" on top of the static main function, it reports "Could not find or load the main class: xxx". However, directly invoking java with the source file works without any error. I tried to use the "Java: Clean the Java Language Server Workspace" command, and error persists.

By looking at the log (, here are two errors reported that may be the cause of the issue:

[2019-10-02 16:48:22.718] [exthost] [error] [redhat.java] provider FAILED
[2019-10-02 16:48:22.720] [exthost] [error] Error: The request (id: 28, method: 'textDocument/hover') has been cancelled
	at c:\Users\tingh\.vscode\extensions\redhat.java-0.50.0\dist\extension.js:1:68555
	at c:\Users\tingh\.vscode\extensions\redhat.java-0.50.0\dist\extension.js:1:68849
	at Immediate.module.exports.M.G.Y.size.setImmediate (c:\Users\tingh\.vscode\extensions\redhat.java-0.50.0\dist\extension.js:1:69210)
	at runCallback (timers.js:694:18)
	at tryOnImmediate (timers.js:665:5)
	at processImmediate (timers.js:647:5)
[2019-10-02 16:48:23.302] [exthost] [info] ExtensionService#_doActivateExtension ms-vscode.cpptools {"startup":false,"activationEvent":"onDebug"}
[2019-10-02 16:48:23.302] [exthost] [info] ExtensionService#loadCommonJSModule file:///c:/Users/tingh/.vscode/extensions/ms-vscode.cpptools-0.25.1/dist/main
[2019-10-02 16:48:23.429] [exthost] [info] ExtensionService#_doActivateExtension vscode.debug-server-ready {"startup":false,"activationEvent":"onDebugResolve"}
[2019-10-02 16:48:23.429] [exthost] [info] ExtensionService#loadCommonJSModule file:///c:/Program Files/Microsoft VS Code/resources/app/extensions/debug-server-ready/dist/extension
Environment
  • Operating System: Windows 10 x64 Pro 1903, Build 18362.356
  • JDK version: Oracle Java 12.0.2
  • Visual Studio Code version: 1.38.1
  • Java extension version: 0.50.0
  • Steps To Reproduce

    Sample Project: (FileIO.java)

    import java.io.File;
    import java.io.IOException;
    import java.util.Scanner;
    public class FileIO {
        public static void main(String[] args)
        throws IOException {
            File file = new File("data.txt");
            Scanner fileInput = new Scanner(file);
            for(int i = 0; i < 5; i++) {
                System.out.println(
                    i + ": " + fileInput.nextDouble()
            fileInput.close();
    
    Current Result
    c:\Research\test_jav>cd C:\Research\test_jav && C:\Users\tingh\.vscode\extensions\vscjava.vscode-java-debug-0.22.0\scripts\launcher.bat "C:\Program 
    Files\Java\jdk-12.0.2\bin\java" --enable-preview -Dfile.encoding=UTF-8 -cp C:\Users\tingh\AppData\Roaming\Code\User\workspaceStorage\24ee80637ed5c707879e2f0bc2507a43\redhat.java\jdt_ws\jdt.ls-java-project\bin FileIO
    Error: Could not find or load main class FileIO
    Caused by: java.lang.ClassNotFoundException: FileIO
    
    Expected Result
    c:\Research\test_jav>"C:\Program Files\Java\jdk-12.0.2\bin\java" FileIO.java
    0: 11.0
    1: 22.0
    2: 33.0
    3: 44.0
    4: 55.0
    
    Additional Informations