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

ArrayIndexOutOfBoundsException

 
Natalia Sandacz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Natalia Sandacz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should name class "Rectangle 1 2" instead "Rectangle"?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Natalia Sandacz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works. Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic