|
|
#1 | |
|
Fully Optimized
|
I went back to an old program I was working on and now it won't work at runtime.
The issue starts right at the beginning where I have the statement: Code:
Scanner in = new Scanner(System.in); Quote:
__________________
Killing under the cloak of war is no different than murder Kein Alkohol ist auch keine Lösung! |
|
|
|
|
|
|
#2 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
It's not to do with \n being appended anywhere - calling nextInt() with a blank string will always result in an InputMismatchException because an empty string can't sensibly be parsed as an integer.
If you want to guard against this (and other illegal entries) then check using the "hasNextInt" method on the scanner object first. If it returns true you can go for it, otherwise you know to halt and do something else.
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
|
|
#3 |
|
Site Team
|
^^ Assuming that's already being done, I'd reinstall your JDK and see if that helps at all.
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it" Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz) |
|
|
|
|
|
#4 |
|
Fully Optimized
|
Geez...I tried your fix, berry, and while that worked (sort of) I ended up with so many other runtime problems. I don't what the hell happened but now functions no longer work properly and the program is basically set to be abandoned now.
It's not important that it works now. It was actually a term project for a class a year or so ago that I was hoping to improve on for just the heck of it. It worked at the time I submitted it so that's all that matters. Oh well....new project!
__________________
Killing under the cloak of war is no different than murder Kein Alkohol ist auch keine Lösung! |
|
|
|
|
|
#5 |
|
Site Team
Join Date: Jul 2009
Posts: 2,627
|
Feel free to send it my way if you like - I like a good Java puzzle to solve now and again
__________________
Save the whales, feed the hungry, free the mallocs. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|