I am new to java. when i try some code, i get the 'Caught ArrayIndexOutOfBoundsException: 0' message. i need help how to address the problem.
the code was as follows. I am leaving out the class name (first line)

public static void main(String[] args){
    


      try {

      double hours = Double.valueOf(args[0]).doubleValue();
      double rate = Double.valueOf(args[1]).doubleValue();
      double pay;


      hours = 0;
      if (hours > 40) {
        pay = rate * 40 + 1.5 * rate * (hours - 40);
      }
      else {
        pay = rate * hours;
      }

      System.out.println("The paycheck is " + pay + " dollars.");
      
    } catch (ArrayIndexOutOfBoundsException e) {
         System.err.println("Caught "
                     + "ArrayIndexOutOfBoundsException: "
                     +   e.getMessage());
    }
      
    }

thanks

Recommended Answers

All 4 Replies

First, there is a Java forum, which would have been a much more appropriate place than Community Feedback.

Now as far as the index out of bounds - did you supply any command line arguments when you ran this? Because it requires two.

Ezzaral:

Thanks for the quick reply. my problem is how to pass the arguments from IDE. I would appreciate if you direct me to the java forum.

thanks

Ezzarel
i got the java forum

It depends on your IDE, but there should be something in Project Properties or your run configuration that allows you to put in arguments. If you are using Netbeans, it can be found under "Project Properties > Run > Arguments".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.