• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

ArrayIndexOutOfBound Help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are my two classes :

When I run the main method it gives me ArrayIndexOutOfBound :




 
author
Posts: 23901
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahza Nassah wrote:
When I run the main method it gives me ArrayIndexOutOfBound :



Please TellTheDetails. What is the message that comes with the exception? Have you examined the stack trace? And what is it that you don't understand?

Henry
 
Rahza Nassah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Rahza Nassah wrote:
When I run the main method it gives me ArrayIndexOutOfBound :



Please TellTheDetails. What is the message that comes with the exception? Have you examined the stack trace? And what is it that you don't understand?

Henry



This is the message :
java.lang.ArrayIndexOutOfBoundsException: -1
at Stack.getTop(Stack.java:31)
at Prefix.preFix(Prefix.java:68)
at Prefix.main(Prefix.java:10)

No, I haven't.

Is my code giving -1 to the index somewhere or something?
 
Henry Wong
author
Posts: 23901
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahza Nassah wrote:
This is the message :
java.lang.ArrayIndexOutOfBoundsException: -1
at Stack.getTop(Stack.java:31)
at Prefix.preFix(Prefix.java:68)
at Prefix.main(Prefix.java:10)

Is my code giving -1 to the index somewhere or something?



The stack trace is your friend. You really should learn how to read it.

It is saying that you are ...

java.lang.ArrayIndexOutOfBoundsException: -1



passing "-1" to dererefence an array at ...

at Stack.getTop(Stack.java:31)



in the getTop() method of the Stack class ... which is near line 31 of the Stack.java source file.

It is also saying that it was called from ...

at Prefix.preFix(Prefix.java:68)



the prefix() method of the the Prefix class ... which is near line 68 of the Prefix.java source file. etc. etc. etc. until it goes all the way back to the main() method.

Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic