3

I recently installed Visual Studio Code and tried to run a simple program

import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
   System.out.print("Hello World");
}

}

but I got this

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at HelloWorld.main(nush.java:3)

I'm using java development kit 11.0.1 and this is my launch.json

{
"configurations": [
    {
        "type": "java",
        "name": "CodeLens (Launch) - HelloWorld",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopOnEntry": false,
        "mainClass": "HelloWorld",
        "args": ""
    }
]

}

4
  • 4
    Looks like your class name and the file name differs. Make sure to rename everything to same e.g. class HelloWorld in HelloWorld.java file. Commented Nov 23, 2018 at 19:31
  • Welcome to Stack Overflow! Please take the tour and visit our help center to learn what kinds of questions are appropriate for this site. If you can edit your question to fit the requirements of this site, please do so. Commented Nov 23, 2018 at 19:32
  • 1
    Also, please do not post images of code or errors, because it makes it more difficult for us to help you with your issue. It is always better to copy and paste the relevant code and/or errors into your question directly. Please read Why not to upload images of code on SO when asking a question?, then edit your question accordingly. Commented Nov 23, 2018 at 19:33
  • Thank you! That worked. Commented Nov 23, 2018 at 19:34

3 Answers 3

15

public class HelloWorld must be saved in a file named HelloWorld.java, not nush.java

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. That helped a lot!
-1

Just follow the steps below... It solved my problem

In VS CODE... Clean the java language server workplace

Comments

-1

Class name should be similar to the file name. Refactor the file name as below or vice versa. Class name = HelloWorld File name = HelloWorld.java

1 Comment

This is the same solution as in the accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.