0

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 by Nick Evan: added code-tags

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Ezzaral
0

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 by Ezzaral: n/a

0

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.