Guys why is VSCODE unable to find main method when it's already there ?
static void sayHello(String name) {
System.out.println("Hello" name);
}
public static void main(Strings[ ]args) {
sayHello("David");
}
A screenshot
I also tried adding a class but.. Didn't work.
CodePudding user response:
The thing with java is that you want every thing to be inside a class. and, remember this important bit - "the class name should match the file name." so, that is probably the issue. i.e. - in 1, code isn't inside any class. in second, the class name doesn't match the file name. if you are new to java, I suggest going through w3's java tutorial this is a text based tutorial so, you can keep your own pace or even speed run through it [do try out every thing they teach by yourself too]. I seriously recommend it since I started there and almost finished it within 1-2 weeks without any help.
CodePudding user response:
S in String in public static void main(String[] args) {
Should be in Uppercase.Error
CodePudding user response:
- Your java file's name doesn't match the class name. Please rename your .java file as
hello.java
. - Pay attention to the args in main method should be
String[]
, while it'sStrings[]
in your screenshot. - The white dot after your .java file means your file wasn't saved. Save it before running.
hello.java:
public class hello{
public static void main(String[] args) {
System.out.println("hello world");
}
}
Please correct the above things, after Java: Clean Java Language Server Workspace
from command Palette the run again.