Results 1 to 17 of 17
Like Tree2Likes
  • 1 Post By Tolls
  • 1 Post By Tolls

Thread: Enum Class Throwing IllegalArgumentException ?

  1. #1
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Exclamation Enum Class Throwing IllegalArgumentException ?

    I have a enum class which contains some string which i am comparing to a string i get from a user

    Java Code:
    public enum Compare{
    a, b, c, d, e, f
    }
    
    class SomeClass{
    
    String method(String letter){
     Compare word= Compare.valueOf(letter);
    
    }
    }
    Everything works fine but when I added a new word to it like "g" it throws the IllegalArgumentException ?
    I have no Idea what I am doing wrong,
    Help,
    Last edited by Rana Muhammad Waqas; 03-05-2015 at 08:38 AM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Probably you did not add a value 'g' to your compare enum at all. But that is only guessing when you only say that "it" throws an exception without specifying what "it" is, or posting the actual exception stacktrace.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Well, I have added the new 'g' into the enum class and The exception is given below which says no enum constant

    ex = (java.lang.IllegalArgumentException) java.lang.IllegalArgumentException: No enum constant com.ef.apps.eventcommand.GenericCTICommandType.UPD ATECALLVARIABLE

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Then you are not running the code you think you are.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Well, I have debugging running which shows me line by line where it is going, and I am sure what project I am running

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Could you post a small, complete program that compiles, executes and shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Quote Originally Posted by Rana Muhammad Waqas View Post
    Well, I have debugging running which shows me line by line where it is going, and I am sure what project I am running
    No guarantee as the debugger simply supplies line numbers and values.
    It does not check that those line numbers are valid in the source code you are looking at.

    Get it to log the EnumSet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Rana, you need to learn and follow the Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    @Norm
    I have made this short video which shows the two scanario one which is working fine and the other which is throwing IllegalArgumentException
    Please have a look http://youtu.be/5aW7HSv_Tpc
    Last edited by Rana Muhammad Waqas; 03-04-2015 at 03:41 PM.

  10. #10
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Quote Originally Posted by DarrylBurke View Post
    Rana, you need to learn and follow the Code Conventions for the Java Programming Language: Contents

    db
    Thank you
    and sorry for using bad conventions

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Wait a minute. That code would never compile.

    "class enum compare" is wrong. It is either "class compare" or "enum compare."
    And you don't have the appropriate number of curly braces in your class.
    And you don't return anything from the method.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Thank you for your corrections,
    I just wrote this dummy code to explain the situation in hurry,
    I guess I am used to the IDE error highlights and auto-fill
    Last edited by Rana Muhammad Waqas; 03-04-2015 at 03:23 PM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Could you post a small, complete program that compiles, executes and shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Quote Originally Posted by Rana Muhammad Waqas View Post
    @Norm
    I have made this short video which shows the two scanario one which is working fine and the other which is throwing IllegalArgumentException
    Please have a look http://youtu.be/5aW7HSv_Tpc
    Instead of posting a video, post the real enum here, and the full exception, including stack trace.
    I notice you are simply printing the message.
    Use printStackTrace instead, or a proper logging setup.

    There's no point posting stuff that is not your actual code.

    I still maintain that it is likely you are not running the code you think you are.

    Indeed, if you look at your vid you will see that the new enum value is not recognised when you go into the source code (look at the text when you hover over it).

    You have not deployed the new version into the module that you are running your tests from.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    Join Date
    Mar 2015
    Posts
    8
    Rep Power
    0

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Thank you for your patience and help,
    Yes you are right, I was using the old JAR which didn't have the updated code,
    But there is a strange thing, I have included the Jar in it of my SDK and when I debug it in Netbeans it doesn't take me to the jar or refer anything to jar instead it start debugging in the project from which I have build the JAR, Why is that?
    Last edited by Rana Muhammad Waqas; 03-05-2015 at 08:37 AM.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Because that's the source code associated with the jar file as far as Netbeans is concerned.
    As I said, the debugger takes no account of whether that source code actually produced the jar that is being executed.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Enum Class Throwing IllegalArgumentException ?

    Rana, please don't edit your posts after there are responses, as that destroys the context of the advice given.

    For reference, the original post (before it was edited a number of times) is as below.

    db

    Quote Originally Posted by Rana Muhammad Waqas View Post
    I have a enum class which contains some string which i am comparing to a string i get from a user
    Java Code:
    class enum compare{
      a, b, c, d, e, f
    }
    class someClass{
      String method(String letter){
      String Word= compare.valueOf(commandType);
    }
    Everything works fine but when I added a new word to it like "g" it throws the IllegalArgumentException ?
    I have no Idea what I am doing wrong,
    Help,
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 08-23-2013, 04:03 PM
  2. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 10:45 AM
  3. how to use this enum class
    By thorbcn in forum New To Java
    Replies: 1
    Last Post: 07-04-2011, 02:29 AM
  4. Class enum expected
    By Tyre in forum New To Java
    Replies: 10
    Last Post: 04-16-2011, 07:25 PM
  5. Replies: 11
    Last Post: 11-05-2009, 12:44 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
  •