Java Error eclipse String

I am new to Java and I follow some instructions. However, when I go to the "Lines" section

public class String { public static void main(String[] args) { java.lang.String name; name = "luke"; System.out.println("Hello, " + name + "pleased to meet you"); } } 

But I get

 Error: Main method not found in class String, please define the main method as: public static void main(String[] args) 
+4
source share
5 answers

If you insist on using String as the name of your class, this should be:

 public class String { public static void main(java.lang.String[] args) { java.lang.String name; name = "luke"; System.out.println("Hello, " + name + "pleased to meet you"); } } 

I don't think it is especially wise to try and reuse the class names defined in java.lang though.

+6
source

Since your class has the name String, it is output by the compiler as the argument type of your main method.

Try to fully determine the type of argument:

 public static void main(java.lang.String[] args) { ... 

Or better yet, rename the class to use and the class name is non-java.lang.

+5
source

You tried to fully qualify your reference to java.lang.String for the variable name , but not for the args parameter for main .

Using

 public static void main(java.lang.String[] args) { 

Of course, all this was caused by the fact that you called your String class the same name as the built-in class in Java. Perhaps you could call it StringTest instead? This avoids having to worry about class name collisions and fully qualifies the embedded Java String .

+5
source

As your class hides the name java.lang.String , you need to write

 public static void main(java.lang.String[] args) { 

Better name your StringTest class or something else to avoid this confusion.

 public class StringTest { public static void main(String[] args) { String name = "luke"; System.out.println("Hello, " + name + "pleased to meet you"); } } 
+2
source

why don't you try this

 public class StringFirstTry { public static void main(String[] args) { String name; name = "luke"; System.out.println("Hello, " + name + "pleased to meet you"); } 

}

0
source

Source: https://habr.com/ru/post/1481834/


All Articles