Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Error in Eclipse, Norm redirected me here.

  1. #1
    Member
    Join Date
    Feb 2012
    Location
    West USA
    Posts
    67
    My Mood
    Inspired
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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:

    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
     
     
    			}
     
    }
    Last edited by SilentNite17; February 14th, 2012 at 09:41 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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?

  3. #3
    Member
    Join Date
    Feb 2012
    Location
    West USA
    Posts
    67
    My Mood
    Inspired
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

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

Similar Threads

  1. Replies: 2
    Last Post: October 30th, 2011, 06:37 PM
  2. Replies: 0
    Last Post: October 14th, 2011, 11:03 AM
  3. Error Running Java in Eclipse
    By steadyonabix in forum Java IDEs
    Replies: 1
    Last Post: September 3rd, 2011, 10:28 PM
  4. Error when opening eclipse
    By BlackJavaCoder in forum Java IDEs
    Replies: 4
    Last Post: September 3rd, 2011, 07:57 AM