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 ArrayIndexOutOfBoundsException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayIndexOutOfBoundsException" Watch "ArrayIndexOutOfBoundsException" New topic
Author

ArrayIndexOutOfBoundsException

Natalia Sandacz
Greenhorn

Joined: Jul 03, 2011
Posts: 6
Hi!
I wanted to compile such program:

Unfortunately it doesn't work and I get : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at EnterValuesFromKeyboard.main(Rectangle.java:14)
How can I fix it?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

Natalia,
Welcome to CodeRanch!

As a matter of semantics, your program is giving a runtime error which means it does compile.

The error implies you are calling it as "java Rectangle" instead of "java Rectangle 1 2". If this is not the case, can you show how you are running the program?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Natalia Sandacz
Greenhorn

Joined: Jul 03, 2011
Posts: 6
I should name class "Rectangle 1 2" instead "Rectangle"?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

No. The name is good. When you run the program, you can optionally supply arguments. This is where the 1 and 2 fit in.

so:
javac Rectangle.java
java Rectangle 1 2
Natalia Sandacz
Greenhorn

Joined: Jul 03, 2011
Posts: 6
I use JCreator. When I run the program I can't supply any arguments (or I don't know how to do it). In build output I have: Process completed. but in General output I have Exception.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

I myself have not used the JCreator IDE. But can you try the steps under Setting Up Command-Line Arguments topic in a JCreator tutorial link -> a JCreator tutorial and give 1 2 as arguments for the Main method as given in the picture?

Its similar to running java Rectangle 1 2 i think.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I would advise you not to use an IDE for now. At this point you're not familiar with the basics and using by using just a text-editor and a compiler you'll pick those basics up much faster.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Natalia Sandacz
Greenhorn

Joined: Jul 03, 2011
Posts: 6
It works. Thanks a lot!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ArrayIndexOutOfBoundsException