PDA

View Full Version : Java input help


Blacknight962
02-27-2009, 06:13 AM
Solved

Gox
02-27-2009, 07:09 AM
JOptionPane.showInputDialog always returns a String, and thus you cannot assign the return value to Monster because it is of type int.

Try the following:
int Monster = Integer.parseInt(JOptionPane.showInputDialog("Monster ID?"));

Or something similar...
parseInt method description:
Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002d') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.

Parameters:
s - a string.
Returns:
the integer represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable integer.
http://java.sun.com/j2se/1.3/docs/api/java/lang/Integer.html

Blacknight962
02-27-2009, 07:52 PM
Thanks!