Error in Eclipse, Norm redirected me here.
Hello.
I have written a Java code whitch is supposed to coose a random card suit from
enum Suits { Club, Diamond, Spade, Heart }
and you are supposed to guess it. The computer will tell you if you got it wrong.
I seem to have solved all of the code problems, but Eclipse if having a problem with the code. When I run it, it gives the error:
Error: Main method not found in class Cards$Suits, please define the main method as:
public static void main(String[] args)
Norm redirected me here because he thought I was having a problem with the IDE and that my code compiled correctly without the IDE.
Help?
-Silent
EDIT::::::::::::::::::::::::::
Woops, I did not post the code. Here is is:
Code java:
import java.util.Scanner;
public class Cards {
enum Suits { Club, Diamond, Spade, Heart }
public static void main(String[] arg) {
String userInp;
String realSuit;
int randomNumber;
Scanner scan=new Scanner(System.in);
randomNumber= (int) (((double) 3*Math.random() ) + 1);
System.out.print("I'm thinking of a suit. Can you guess what it is?");
userInp=scan.nextLine();
switch ( randomNumber ) {
case 1:
realSuit="Club";
break;
case 2:
realSuit="Diamond";
break;
case 3:
realSuit="Diamond";
break;
default:
realSuit="Heart";
break;
} //end of switch
if (userInp==realSuit) {
System.out.print("You got it right!");
}
else {
System.out.print("You got it wrong.");
} //end of if statement
}
}
Re: Error in Eclipse, Norm redirected me here.
The problem appears to be that the IDE is NOT issuing the command: java Cards
to execute the program. From the error it looks it is doing: java Cards$Suits
What is the filename of your source file?
Re: Error in Eclipse, Norm redirected me here.
Can you please elaborate on what a source file is? I'm sorry, I am a beginner and I have not yet learned what that is or how to find it.
If you do not want to elaborate, that is fine, because I just found out that compiling it in the cmd works fine, but it doesn't work in Eclipse (is this because Eclipse is and IDE and the error I've been getting is coming from the IDE itself and not the compiler?)
-Silent
Re: Error in Eclipse, Norm redirected me here.
Look at this part of the tutorial. It starts explaining things:
"Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)
The error message was when you tried to execute the code, not compile it.