Page 1 of 1

Simple class problem

Posted: Thu Jan 16, 2003 8:03 pm
by kev
I am having trouple with this simple class:

/** test
* @KPB
*/

public class testofclass
{
static final double RATE = 0.05;
static double purchase;

public static void main(String[] args)
{
double tax;
double total;
purchase=Double.parseDouble(args[0]);
tax = RATE * purchase;
total = purchase + tax;
System.out.println("Total: " + total);
}
}


****
When I compile(which works fine) and run this application, I get this error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at testofclass.main(testofclass.java:14)


Can anyone provide a quick fix?

Re: Simple class problem

Posted: Fri Jan 17, 2003 4:36 pm
by emann
args[0] = your program name

try
purchase=Double.parseDouble(args[1]);

Re: Simple class problem

Posted: Mon Jan 20, 2003 8:41 am
by Henrik S. Larsen
Not in java :-)

args[0] is the first argument / parameter to the class.
Seems to me, that you are running the class without any arguments

Re: Simple class problem

Posted: Sat Feb 01, 2003 11:23 pm
by Ted Herman
Yes, I don't think you can define static constants in a class with the main method...