Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me Pls.

 
Sultan Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sultan Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnk you Blake Minghelli
it work now

 
Sadanand Murthy
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic