• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndexOutOfBound Help  RSS feed

 
Rahza Nassah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are my two classes :

When I run the main method it gives me ArrayIndexOutOfBound :




 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!