File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help me Pls. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help me Pls. " Watch "Help me Pls. " New topic
Author

Help me Pls.

Sultan Aziz
Greenhorn

Joined: Feb 06, 2004
Posts: 4
Hi,
This program give me

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
)at Rect.main(Rect.java:13

class Area{
void Rectangle(double L, double W){
double A;
A=L*W;
System.out.println("A = "+A);
}
}
class Rect{
public static void main(String args[]){
Area R=new Area();
double L=Double.parseDouble(args[0]);
double W=Double.parseDouble(args[1]);
R.Rectangle(L,W);
}
}
NOTE:
I am using JCreator.
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Originally posted by Sultan Aziz:
Hi,
This program give me

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
)at Rect.main(Rect.java:13

class Area{
void Rectangle(double L, double W){
double A;
A=L*W;
System.out.println("A = "+A);
}
}
class Rect{
public static void main(String args[]){
Area R=new Area();
double L=Double.parseDouble(args[0]);
double W=Double.parseDouble(args[1]);
R.Rectangle(L,W);
}
}
NOTE:
I am using JCreator.

Using the command line:
java Rect 5 5
A = 25
It seems to work fine. I've never used JCreator, does it give you options to run your program with arguments?


Thanks, leo
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
You are getting the ArrayIndexOutOfBoundsException because you have not passed any arguments into your app when you start it (i.e. when you run it in JCreator). args[0] references the first argument and args[1] references the second argument.
By default, when you run a java app in JCreator, it does not give you the chance to specify the "main" arguments. To turn that feature on:
1. Go to Tools --> Options
2. In the "Options" dialog box, select "JDK Tools" on the left.
3. In the "Select Tool Type" drop-down, select "Run Application" and then select "<default>"
4. Click the "Edit" button
5. Select the "Parameters" tab
6. Check the option "Prompt for main method arguments"
7. Click OK
The next time you do a Build --> Execute File, you should get an input box where you can specify the arguments you wish to pass to the main method. Enter each argument with a space between.
[ February 06, 2004: Message edited by: Blake Minghelli ]

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Sultan Aziz
Greenhorn

Joined: Feb 06, 2004
Posts: 4
Thnk you Blake Minghelli
it work now

Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by Sultan Aziz:
Thnk you Blake Minghelli
it work now


Hi Sultan, I'll assume you are ver new to java and hence this response. The stack trace that gets printed when an exception occurs, often will tell you (text in parentheses are from your example):
  • The exception that occurred (ArrayIndexOutOfBoundsException)
  • The method that this exception occurred in (main)
  • The .java file that this method is in (Rect.java)
  • The actual line # that the exception occurred in (13 in Rect.java:13 is the line # that caused the exception)

  • Armed with this information, you can see the offending line of code and then do some deductive analysis as to the cause of the exception.


    Ever Existing, Ever Conscious, Ever-new Bliss
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Help me Pls.