Why do I get I get this error?
java.lang.NumberFormatException: For input string: "game"
Update:args = [game]
java.lang.ArrayIndexOutOfBoundsException: 1
Is what the console is displaying, sorry I didn't mention this, But i'm a java noob..
Copyright © 2024 Q2A.MX - All rights reserved.
Answers & Comments
Verified answer
game is not an Integer, it is a String -- if you entered 145, then Integer.parseInt(arg[0]); would work as it is supposed to work
It's because your first argument is "game" and not the string representation of a number.
To see what's in the args[] array, add the following as the first line of main()to the front of main:
System.out.println( "args = " + java.util.Arrays.toString( args ) );
Because your didn't give a number for your first command-line argument? The code as written assumes/requires that the first command-line argument be a valid integer.
So it expects something like:
java your.package.YourClass 44 [other arguments]
And not
java your.package.YourClass game 33 [other arguments]
@M