Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to avaoid java.lang.IllegalArgumentException: No enum const class

912973May 17 2012 — edited May 21 2012
HI ,

Iam getting java.lang.IllegalArgumentException when iam using switch case through Enum contants.

//Enum Constants declaration
public enum USEOFPROCEEDSVALUES { U1,U2,U3, U4}




//Using Enum in Java class
Test.java

USEOFPROCEEDSVALUES useOfProceedsVar =USEOFPROCEEDSVALUES.valueOf(useOfproceeds);

switch (useOfProceedsVar) {
case U1:

revenueSourceCode="REVENUE_SOURCE_CODE.POWER";

break;
case U2:
revenueSourceCode="REVENUE _SOURCE_CODE.WATER";
break;
case U3:
revenueSourceCode="REVENUE_SOURCE_CODE.POWER";
break;
case U4:
revenueSourceCode=REVENUE_SOURCE_CODE.POWER";
}
break;
default:
revenueSourceCode=null;



Exception raising if there is either of these not U1,U2,U3,U4 ara not avalabele. i.e is if useOfProceedsVar is A6 then exception raising

How to avoid this exception

Thanks for early reply

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 18 2012
Added on May 17 2012
8 comments
14,309 views