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

Edited 6 Years Ago by Nick Evan: added code-tags

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.

Edited 6 Years Ago by Ezzaral: n/a

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

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".

This article has been dead for over six months. Start a new discussion instead.