0
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

NiziL
5,1401 gold badge26 silver badges34 bronze badges
asked Mar 3, 2015 at 11:58
2
  • 5
    How 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? Commented Mar 3, 2015 at 12:00
  • 2
    Well, I'd avoid notepad ;) Commented Mar 3, 2015 at 12:04

3 Answers 3

1

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.

answered Mar 3, 2015 at 12:15
Sign up to request clarification or add additional context in comments.

1 Comment

Created a new project and it works now , old one still doesn't work thou` and same code . Edit : you were right , i created a class named "string" because I was at string examples , deleted it and it works now , Thank you. SOLVED
0

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.

answered Mar 3, 2015 at 12:13

1 Comment

I have like 15 classes but won't work any of them now , and worked yesterday , dunno whats wrong, Ill try your method . thank you
0

The 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.

answered Mar 3, 2015 at 12:04

5 Comments

I am using Eclipse IDE
The problem is that all my programs keep giving the same error now , and worked just fine yesterday.
i change my post. pls check
Created and new project and it works now , dunno what was with the last one , same code doesn't work in that project
Nice!! I hope it helped

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.