This is not an issue with JGrasp -- it's the code itself.
When you say "args" you are referencing the first element in the array args. However, if this array has a length of zero -- which happens when the program is run without any command line arguments -- then the exception results.
You can avoid this by checking the array's length first. For example...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jun 27, 2007
Ok I think I get it. So I am not giving the programming anything to go on, it's just saying (yes, I am personifying a computer program) "This is the way it is, so this is what I am going to do" as opposed to an "if/then" giving it a one or the other. But this has nothing to do with allowing the user to input an argument, right?
Originally posted by Jake Miller: So I am not giving the programming anything to go on, it's just saying (yes, I am personifying a computer program) "This is the way it is, so this is what I am going to do" as opposed to an "if/then" giving it a one or the other...
Right. When you use args without checking first, you are assuming that the program is being provided these arguments and args actually exists. If that assumption is wrong, then the program will fail. By checking this assumption, you can make the program more flexible and more forgiving of user error. You can basically say, "In most cases, I expect this to run using arguments in the args array. But if the user forgets, I'll resort to default values, or maybe I'll prompt the user for input," which (I think) is your next question...
Originally posted by Jake Miller: ... But this has nothing to do with allowing the user to input an argument, right?
If you want the user to be able to "interact" with the program while it's running, you need a way to get their input. For example, an instance of Scanner...
An alternate approach is to check the input command-line arguments. Remember they constitute an array, and every array has a length field. You can put in a check forand you have various options for the else, eg
print out "usage java RadiusToArea <radius>"
choose a default value
Close the program
BTW: You might find Double.parseDouble(args) simpler to write.