This document provides the information needed to troubleshoot common errors of Debugger for Java (the debugger). If it does not cover the problem you are seeing, please log an issue instead.
The debugger works with Language Support for Java(TM) by Red Hat (the language server) for source mapping and project support. If the language server fails to start, the debugger will not work as expected. Here is a simple way to check whether the language server is started. Open a .java or a Java project folder in VS Code, and then check the icon at the right side of the status bar. You should see the 👍 icon if the language server is loaded correctly.
- If you get the error "The JAVA_HOME environment variable points to a missing folder" or "Java runtime could not be located", please make sure that the environment variable JAVA_HOME points to a valid JDK. Otherwise, ignore this step.
- Open your Maven pom.xml file or Gradle build.gradle file, then run VS Code command "Java: Update project configuration" to force the language server to update the project configuration/classpath.
- Try cleaning the stale workspace cache. Quit all VS Code processes and clean the following cache directory:
- Windows : %APPDATA%\Code\User\workspaceStorage\
- MacOS : $HOME/Library/Application Support/Code/User/workspaceStorage/
- Linux : $HOME/.config/Code/User/workspaceStorage/
- Try more troubleshooting guide from the language server product site.
Below are the common failure reasons.
- 'C:\demo\org\microsoft\app\Main.java' is not a valid class name.
- Main class 'org.microsoft.app.Main' doesn't exist in the workspace.
- Main class 'org.microsoft.app.Main' isn't unique in the workspace.
- The project 'demo' is not a valid java project.
In launch mode, the debugger resolves the classpaths automatically based on the given mainClass
and projectName
. It looks for the class specified by mainClass
as the entry point for launching an application. If there are multiple classes with the same name in the current workspace, the debugger uses the one inside the project specified by projectName
.
- Check whether the class name specified in
mainClass
exists and is in the right form. The debugger only works with fully qualified class names, e.g.org.microsoft.app.Main
. - Check whether the
projectName
is correct. The actual project name is not always the same to the folder name you see in the File Explorer. Please check the value specified byprojectDescription/name
in the .project file, or theartificatId
in the pom.xml for maven project, or the folder name for gradle project. - If the problem persists, please try to use the debugger to regenerate the debug configurations in launch.json. Remove the existing launch.json file and press F5. The debugger will automatically generate a new launch.json with the right debug configurations.
The value specified in request
option of launch.json is incorrect.
- Reference the VS Code official document launch configurations about how to configure launch.json.
- Try to use the debugger to regenerate the debug configurations in launch.json. Remove the existing launch.json file and press F5. The debugger will automatically generate a new launch.json with the right debug configurations.
This error indicates you are doing Hot Code Replace
. The Hot Code Replace
feature depends on the underlying JVM implementation. If you get this error, that indicates the new changes cannot be hot replaced by JVM.
- Restart your application to apply the new changes. Or ignore the message, and continue to debug.
- You can disable the hot code replace feature by changing the user setting
"java.debug.settings.enableHotCodeReplace": false
.
This error indicates you are debugging a remote Java application. The reason is that you don't configure the remote machine's host name and debug port correctly.
- Check whether the remote Java application is launched in debug mode. The typical command to enable debug mode is like "java -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n -classpath <classpath list> MyMainClass", where the parameter "address=5005" represents the target JVM exposes 5005 as the debug port.
- Check the debug port is not blocked by the remote machine's firewall.
There are two possible reasons for this error.
- Reason 1: you try to evaluate an expression when the target thread is running. Evaluation only works when your program is on suspend, for example, stopping at a breakpoint or stepping in/out/over.
- Reason 2: you take the VS Code DEBUG CONSOLE view for program input by mistake. DEBUG CONSOLE only accepts input for evaluation, not for program console input.
- For Reason 1, try to add a breakpoint and stop your program there, then evaluate the expression.
- For Reason 2, try to change the
console
option in the launch.json toexternalTerminal
orintegratedTerminal
. This is the official solution for program console input.
You configure the incorrect main class name in mainClass
of launch.json.
- Check whether the class name specified in
mainClass
exists and is in the right form. - If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the language server troubleshooting paragraph for more troubleshooting info.
This error indicates your application attempts to reference some classes which are not found in the entire classpaths.
- Check whether you configure the required libraries in the dependency settings file (e.g. pom.xml).
- Run VS Code command "Java: Force Java compilation" to force the language server to rebuild the current project.
- If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the language server troubleshooting paragraph for more troubleshooting info.
When the mainClass
is unconfigured in the launch.json, the debugger will resolve a class with main method automatically. This error indicates the debugger doesn't find any main class in the whole workspace.
- Check at least one main class exists in your workspace.
- If no main class exists, please create a main class first. Otherwise, it's probably because the language server fails to start. Please reference the language server troubleshooting paragraph for more troubleshooting info.
The error indicates your workspace has build errors. There are two kinds of build errors. One is compilation error for source code, the other is project error.
- Open VS Code PROBLEMS View, and fix the errors there.
- If no errors are found in the PROBLEMS View, reference the language server troubleshooting paragraph to update project configuration, and clean workspace cache.