microsoft / vscode-java-debug

Java Debugger for Visual Studio Code.
Other
524 stars 333 forks source link

No delegateCommandHandler for vscode.java.resolveMainMethod #1342

Closed SofijaErkin closed 1 year ago

SofijaErkin commented 1 year ago

[VS Code has prompted "No delegateCommandHandler" while debugging the Java program]

Environment
Steps To Reproduce
  1. Create a java file and the launch JSON file for VS Code, then compile and run.

Compile and run are successful, also, output the result of this java program. just liking:

Screen Shot 2023-05-11 at 22 03 58
  1. Run&Debug using "StartDebugger(F5)" Button

VS Code has prompted "No delegateCommandHandler for vscode.java.resolveMainMethod".

A Sample Project

My workspace, just liking:

testJavaDevelopDemo
|____  .vscode
|           |___ launch.json
|____ testDemo.java

My "testJavaDevelopDemo/.vscode/launch.json" just liking:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "type": "java",
            "name": "Debug (Launch)",
            "request": "launch",
            "mainClass": "${file}",
            "console": "integratedTerminal"
         }
   ]
}

My "testJavaDevelopDemo/testDemo.java' just liking:

public class testDemo {
    public static void main(String[] args) {
           int a=1;
           int b=2;
           int c = a + b;
           System.out.println(a+"+"+b+"="+c);
           System.out.println("hello world");
    }

}
LOGS

Sorry, I had not known how to check out the logs of debugging.

Current Result

The VSCode has prompted "No delegateCommandHandler for vscode.java.resolveMainMethod"

while I click the "Start Debugger(F5)" button. Just like the below picture showing:

delegateCommandHandler
                 Notice Prompt: No delegateCommandHandler for vscode.java.resolveMainMethod
Expected Result

The VSCode could enter Debugger status while I click the StartDebugger(F5) button, just liking the below picture.

Screen Shot 2023-05-11 at 21 55 55
                                Notice: Successfully Start Debugger 
Additional Informations
Try to fix the problem
  1. Restart&Reboot Again Ang Again

I refer the Troubleshooting of vscode-java-debug, restart the "VSCode" once and the issue appear again, then reboot the

laptop and "VSCode", but that still a problem.

  1. Downgrading Version And Reload Required

Also, I found the same error liking #1308, tried to Downgrading versions of

the Test Runner for Java extension, also, I pressed "reload required" button next to the "uninstall" button,

but that did not fix my issue.

SO I have to open this issue!

Java Home configuration

Just add the below code into my ZSH configuration file ~/.zshrc.

JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

Also, I config the "javahome" on the Settings of VSCode.

Others Environment
testforstephen commented 1 year ago

Java extension version: (Language Support for Java(TM) by Red Hat) v0.64.1

The latest version of Java Debugger extension is incompatible with RedHat Java extension 0.64.1. To avoid any issues, please update your RedHat Java extension to the most recent version.

SofijaErkin commented 1 year ago

I've just reverted the version of "'Debugger for Java'" from v0.50.0 into v0.20.0, and my Project "testDemo" worked! Also, updating the version of "Language Support for Java(TM) by Red Hat" to the latest "v1.18.0" fixed my trouble. Finally, @testforstephen, thanks so much!