Najat Najat - 1 month ago 7
Java Question

Showing Error in My Java Code

I'm a new Java learner. Can you please help me fix the bug in my code? Here's my program:

public class Third {

public static void main(String[] args) {
String name;
name=new String ("Najat");
System.out.println(name);
}
}


It shows this error:

Error: Main method not found in class Third, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

Answer

Rename your other class called String as you're confusing the JVM. It sees

public static void main(String[] args) {

and thinks that you're referring to your own String class, not java.lang.String