• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

ArrayIndexOutOfBoundsException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should name class "Rectangle 1 2" instead "Rectangle"?
 
Jeanne Boyarsky
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works. Thanks a lot!
 
This tiny ad will self destruct in five seconds.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic