Results 1 to 4 of 4
  1. #1
    ShaneO is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Passing enums through (as parameters)

    Hello,

    I am new to these forums and brand new to Java..

    I'm trying to compile this code with no success.. I am at a loss as to what I could be doing wrong - perhaps some feedback might help me out.

    Java Code:
    public class Parliament {
    
    	// Each member of parliament is assigned the following:
    	// Name, Political Party, and Province
    
    	enum Party {
    		CON, NDP, LIB, GRN, BQC, IND
    	}
    	enum Province {
    		ON, QC, NS, NB, MB, BC, PE, SK, AB, NL, NT, YT, NU
    	}
    
    	String strName;
    	Party enmParty;
    	Province enmProvince;
    	
        public void Parliament(String strName, Party enmParty, Province enmProvince) {
     
            this.strName = strName;
    	this.enmParty = enmParty;
    	this.enmProvince = enmProvince;
    	
    	System.out.println("Name: " + strName);
    	System.out.println("Party: " + enmParty);
    	System.out.println("Province: " + enmProvince);
        }
    }
    It's giving me an error reading:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Forgive me if I'm missing something very obvious.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Passing enums through (as parameters)

    Erm, just a wild guess: your class is missing a static public void main(String[] args) method? (it can't be run by the JVM)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ShaneO is offline Member
    Join Date
    May 2012
    Posts
    7
    Rep Power
    0

    Default Re: Passing enums through (as parameters)

    Thanks!

    And forgive my lack of understanding.. I'm used to VB, and other less common languages (Turing, etc).. all of which seem much, much more simple. (In addition - I have no access to any IDEs)

    Basically, my question now becomes - how do you call a method from the 'public static void main(String[] args)?

    If I wanted to call the Parliament method for user input, I'm thinking it would be similar to:

    Java Code:
    Parliament Member1 = new Parliament();
    Hopefully I'm not too far off..

    Thank you for your much needed help.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Passing enums through (as parameters)

    So now you know that the JVM searches for that main( ... ) method to start executing your program. The statements in the body of that method can do what they want, e.g. create new objects and call methods on that object. Your initialization of the Member1 reference variable makes a fine statement in the body of your main( ... ) method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. passing parameters to graphics
    By jforce93 in forum New To Java
    Replies: 6
    Last Post: 02-04-2010, 03:45 AM
  2. passing parameters to next jsp using javascript
    By sridevisala in forum New To Java
    Replies: 0
    Last Post: 11-20-2009, 05:34 AM
  3. [SOLVED] Passing parameters
    By robocop in forum New To Java
    Replies: 3
    Last Post: 03-03-2009, 10:16 PM
  4. passing parameters to paint mtd
    By themburu in forum Java Applets
    Replies: 3
    Last Post: 07-14-2008, 08:15 PM
  5. JNI - passing and returning parameters by value
    By java_to_c in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 08:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •