package day1.examples;
public class String2 {
public static void main(String[] args) {
String x = "Andrei Vlad";
System.out.println("Hello" + x);
}
}
I keep getting this error when i run it
Error: Main method not found in class day1.examples.String2, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
and on line error it says type mysmatch cannot convert from java lang string etc..
Thank you
-
5How new are you to Java? If we're talking 'reeeaaally new', start with notepad and the command prompt. Did you maybe forgot to save your class after changing it again?Stultuske– Stultuske2015年03月03日 12:00:54 +00:00Commented Mar 3, 2015 at 12:00
-
2Well, I'd avoid notepad ;)Albert– Albert2015年03月03日 12:04:24 +00:00Commented Mar 3, 2015 at 12:04
3 Answers 3
It works for me:
[steve@newbox ~]$ cd /tmp=
[steve@newbox tmp]$ mkdir -p day1/examples
[steve@newbox tmp]$ cat > day1/examples/String2.java
package day1.examples;
public class String2 {
public static void main(String[] args) {
String x = "Andrei Vlad";
System.out.println("Hello" + x);
}
}
[steve@newbox tmp]$ javac -classpath . day1/examples/String2.java
[steve@newbox tmp]$ java -classpath . day1.examples.String2
HelloAndrei Vlad
[steve@newbox tmp]$
The most likely explanation is that you have managed to get Eclipse rather confused.
My initial idea was that this was a homoglyph problem. But provided that you have copy-and-pasted the code correctly, the evidence disproves that.
The other idea I had was that you had mistakenly created your own version of the String class (in the day1.examples package). However, that should have resulted in compilation errors in the initialization of x.
1 Comment
I'd start by trying with a clean of the project. Seems weird you would need to do so with only one class in a single package but it will recompile all of your code for you. Everytime I have an issue that I don't think I should have I always F5 (refresh) my packages and then clean. You'd be surprised how many issues it fixes.
Go to Project --> Clean
Then try running again.
1 Comment
s wrong, Ill try your method . thank youThe code says that there are somethink wrong with your main class but all seems ok.
In Eclipse rigth click on your projects-> run-> run configurations and check if all is ok.