IllegalArgumentException = hard to catch it.. (help)
Hi there,
I've got little problem catching the "IllegalArgumentException", if you guys know how to solve this problem that'd help me a lot..
The code works, but if I type something else than what's assigned in Enum it shows IllegalArgumentException...
TIA
public Options paper, rock, scissors;
//assign variables
paper = Options.paper;
rock = Options.rock;
scissors = Options.scissors;
String Playing;
//here comes the code.... = problem................................
//Select one of these only!
while( !(Options.valueOf(thePlay) == Options.rock) && !(Options.valueOf(thePlay) == Options.paper) && !(Options.valueOf(thePlay) == Options.scissors) )
System.out.println("\n It's your turn select ONE: rock, paper, scissors ");
try{
catch (IllegalArgumentException e)
Playing = scan.next().toLowerCase();
.......Error:
Exception in thread "main" java.lang.IllegalArgumentException: No enum const class...
I see.
A few ways occur to me. Given this:
enum Stuff {dog, cat, monkey}You could do this:
Stuff s = null;
do {
try {
s = Stuff.valueOf(Input.getString());
} catch (IllegalArgumentException e) {
System.err.println("that's not a valid Stuff: " + e);
} while(s == null);
System.out.println("s is: " + s);which works, but is ugly.
Or you could do this:
Stuff s = null;
ASKUSER: while(true) {
String in = Input.getString();
for(Stuff t : Stuff.values()) {
if (t.name().equals(in)) {
s = t;
break ASKUSER;
System.err.println("That's not a valid value: " + in);
System.out.println("s is: " + s);Or you could do this:
Map<String, Stuff> vals = new HashMap<String, Stuff>();
for(Stuff t : Stuff.values())
vals.put(t.name(), t);
// then later:
Stuff s = null;
do {
s = vals.get(Input.getString());
if (s == null)
System.err.println("That's not a valid value");
} while(s == null);
System.out.println("s is: " + s);which might be worthwhile if you're doing a lot of lookups and there are a lot of values in the enum.
Another way which may be best is the following. First, define your enum like this:
enum Stuff {
dog, cat, monkey;
public static Stuff niceValueOf(String s) {
for(Stuff t : values())
if (t.name().equals(s))
return t;
return null;
}Then you could just do this;Stuff s = null;
do {
s = Stuff.niceValueOf(Input.getString());
if (s == null)
System.err.println("That's not a valid value");
} while(s == null);
System.out.println("s is: " + s);I haven't used enums a whole lot myself, so maybe there's a better approach I'm not familiar with.
Similar Messages
-
My iPhone 4 will not sync my new voice memos from the "Voice Memos" app to my computer. This is frustrating, should not be so hard, can someone please help. I use PC with windows 7 with iPhone version 6.1.3 and iTunes most recent. Thanks.
In the Music tab of iTunes, do you have 'Include Voice Memos' checked?
-
I did a software update on my IPhone 4S and now it's frozen at the apple symbol. hard reseting doesn't help??
HELP!!!!!!!That's not a good sign, take your iPhone to a premium reseller or to an Apple Store.
-
My internal hard drive isn't being recognized on my macbook pro but when I put the HD in my Mac Pro (desktop), the desktop computer recognizes the HD. When I insert the installer CD on my laptop, it also doesn't recognize my hard drive. Please help! Thank you!
I've also been getting an image with the folder and question mark. I've tried everything on the apple support page but it doesn't seem to work either.Well, I tried all of your suggestions and they didn't work -- no surprise because I was trying to backup to my external c.d. disk. Duh! The application for the home is in the mail.
-
Hi Everyone. I have an old Mac Book with software updated to 10.6.8. I have saved a ton of emails in my inbox 'On My Mac'. There are so many it is slowing down my computer. Where do I find the folder with all the emails so I can cut and paste them to an external hard drive? Pls.help. Tks.
Depending on which email client software you use
the files should be in 'your home folder' library, esp.
if you use Mail application.... ~/Library/Mail
Since you don't specify what mail application,
that would most be associated with the file.
I notice there are some items to the right of your post
where it says "more like this' so that may be worth a
look to see if similar issues were answered. Also, the
Help viewer in your system is a searchable database.
Seems that google also brings up fair information, too.
Do you have a complete bootable clone of your entire
Mac system on an externally enclosed hard disk drive?
Good luck & happy computing! -
My PC computer was wiped (virus) including itunes. How do I transfer the many playlists and music on my ipod to the new re-installed itunes?? Ipod is synced to old itunes. I have all original music files on external hard drive. Please help?
New itunes is trying to wipe the ipod. But have many many playlists (many hours making) which I want to save. Any help would be appreciated.If you want to just extract the playlists from your iPod, plug it in iTunes. When it appears under devices, right->click on it and choose Export Playlists. Save them to a location such as your desktop and them import them into your library once you have copied and imported all of your music back into it.
See this older post from another forum member Zevoneer covering the different methods and software available to assist you with the task of copying content from your iPod back to your PC and into iTunes.
https://discussions.apple.com/thread/2452022?start=0&tstart=0
B-rock -
MacBook Pro 2010: Flashing folder w/? on not responding to startup keys & I'm trying to install a new hard drive, can anyone help?
Thanks. It started up com that disk but when I went to install it had an error message (didn't get to write out what it said). So I attempted to restore from time machine but it said there was no space, even though it's a new (replacement under warranty) HGST 1TB HD, so I did what I think was right and tried to partition the disk but it now says 'Partition faild...POSIX report...cannot allocate memory'. im not sure what to do, and I'm trying to remember how the previous hd was installed and formatted for use but that was over a year ago now. Should have erased the hd first or something?
-
My hard disk crashed and I cannot find out how to "contact customer service" other than this forum. The website seems to just take me in a circle. I need to de-activate a license but cannot access the software due to a crashed hard drive. Please help.
Hi Anthony ,
Here is the link to connect with Adobe Chat Support.
https://helpx.adobe.com/adobe-connect/kb/connect-chat-support.html
Hope your query gets resolved .
Regards
Sukrit Dhingra -
Hi,disc wiped ,OSX10.9 back on ,how do I restore my data from external hard drive ?Any help welcome .
There's Setup Assistant and Migration Assistant. The cleanest way to do it is Setup Assistant, but you only get that option once when you fire up a fresh install of OSX. If you're past that, you could reinstall OSX by booting with Command-R, or you could use Migration Assistant.
Setup/Migration Assistant instructions:
http://support.apple.com/kb/HT5872 -
I downloaded OS X Lion on my iMac and I'm having problems with my computer waking up after hibernating. I can get to the login screen but my mouse will be frozen. The only fix's is a hard reboot. Any help would be great!
Try resetting the SMC and the PRAM.
1. SMC
Read this and follow the instructions for your kind of mac:
http://support.apple.com/kb/HT3964
2. PRAM
Follow the procedure below:
1. Power down the machine.
2. Locate the following keys on your keyboard in preparation for Step 4:
command–option–P–R
3. Press the ‘power on’ button.
4. Immediately – and before the grey screen appears – hold down ‘command-option-P-R’ all together.
5. Keep them held down until you’ve heard the start-up chime twice. After you release them you should hear it again, and hopefully your Mac will boot up as it should normally. -
Iphone 5 stopped charging and playing music through usb in my 2012 Chevy sonic after iOS 8.1 update. Several friends have same problem. Hard reset didn't help. Help???
Fixed it. It is on Chevrolet's end. Press config to access the configuration settings. Turn menu/tune knob to highlight vehicle settings. Press menu/tune to select the vehicle settings menu. Choose return to factory settings.
-
My whole catalogue was nearly lost due to a failed external hard drive. Professional help recovered photos but I can't find my smart tags. Is it possible they were lost on failed drive?
Hi,
In order to recover the tags/albums, etc, you need to have the catalog db. Since currently you only have images, the organization done in the older catalog is probably lost.
Which version of PSE you have and is there any chance, that you have access to catalog location (default is : %programdata%\adobe\elements organizer\catalogs on Windows and ~/library/app support/adobe/organizer/catalogs on MAC) ?
Thanks
Andaleeb -
phone 5S is in constant rebooting mode, showing Apple Logo on screen and a hard reboot has not helped. What can I do?
Hello sherryfromindiana,
The article linked below details a number of tips that can help get your iPhone sorted and functioning again.
iOS: Not responding or does not turn on
http://support.apple.com/en-us/HT201412
Cheers,
Allen -
Once in awhile my screen will freeze while I'm watching a video. Lately it's happening more often, I'm watching a video and it'll freeze BUT I can still hear the dialogue. Only solution I've found so far is to do a hard shut down. HELP!!
Hi there, im also having this problem, i tried running most of the games on my system, and some that are considered "high end" games, are giving me the exact same problem, but other games are running and im able to message fine, i also got some friends to send me messages, and i can recieve messages perfectly, also i noticed moving the actual window around on the screen or just closing down skype also lags. I have 16GB of ram and 4.4Ghz Octa-Core CPU, i checked my load while on the high end games and it there was more than enough hardware usage left like normal for skype to run, and skype wasnt taking any extra up than before. I also checked by bandwidth and i was having no problems with that as skype would lag even on offline games.
I have tried re-installing under a different directory and still the same problem persists, this has only been a problem within the last 24hrs and i haven't installed any other programs that could affect this at the moment.
*UPDATE* I tried downgrading to an older version of skype, 6.3.0.107. Problem Still persists -
Ava/lang/IllegalArgumentException: Missing protocol separator--pls help
hi guys
i have encounter this error in my coding.i 'm a novice in j2me programming, so pls help me .thanks
Uncaught exception java/lang/IllegalArgumentException: Missing protocol separator.
i think the error is somewhere in that code.
try{
SocketConnection sc = (SocketConnection) Connector.open("socket://localhost:5678",Connector.READ_WRITE);
String uri = "file:c:/commands.txt";
System.out.println("r");
InputConnection conn = (InputConnection)Connector.open( uri,Connector.READ );
int ch;
InputStream in = sc.openInputStream();
OutputStream out=sc.openOutputStream();
while( ( ch = in.read() ) != -1 ){
System.out.print( (char) ch );
out.close();
in.close();
sc.close();
catch(ConnectionNotFoundException e ){}
catch(IOException ioe){}i would really appreciate it if someone would advise me on it.thanksChange the "file:c:/..." to "file://c:/..."
Maybe you are looking for
-
A strange question in me32.
when change the contract confirm quantity use me32,we cann't change the quantity less then price unit,if i do it ,the confirm quantity auto change to price unit's quantity,when trace the code ,we find this code, H-MENGE = EKPO-PEINH * EKPO-BPUMN * 10
-
How to remove all scripts on object instances?
I'm looking for any kind of solution here, besides disabling the warning. I hate it when I'm converting someone else's AS2 project to AS3, and there's code buried on an onstage instance somewhere, which gives me the warning: "Actions on button or Mov
-
[SOLVED] OpenOffice with DOCX support
I have to use sometimes Microsoft Word documents in Microsoft Office 2007 format (.docx) (my boss is fan of this format ), but standart version of OpenOffice doesn't support this format and I should ask my partners to convert it to old Word format. B
-
FM Radio in MP3 Player Not Work
The FM Radio Autoscan function of my newly bought 256MB MuVo TX FM MP3 player does not seem to be functioning properly. During the st time I performed autoscanning, the player was only able to register a few radio channels. Channels like 93.3FM and 9
-
When I export 1080p XLM from imovie 09 into fce4 it appears as 720x480 ???
FCE4 really ***** compared to Adobe Premiere!!! Here's my problem. When I export a 1080p file from imovie09 using the XML export function it appears as 720x480 in fce4 ???? Also will the file suffer from the infamous single frame processing that imov