Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Index Out Of Bounds Exception card layout  RSS feed

 
Alejandro Barrero
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using card layout in an application that has been working correctly for months, but today I started getting an ArrayIndexOutOfBoundsException an I haven't been able to find out anywhere what is causing the problem. The exception shows in the debug window of MyEclipse but doesn't print a stack trace. What the window shows is:
Thread [main] (Suspended (exception ArrayIndexOutOfBoundsException))
JViewport(Container).getComponent(int) line: not available
JViewport.getView() line: not available
JViewport.getViewPosition() line: not available
BasicScrollPaneUI.updateColumnHeader(PropertyChangeEvent) line: not available
BasicScrollPaneUI$.Handler.scrollPanePropertyChange(PropertyChangeEvent) line: not available
...
NewJFrame(Frame).addNotify() line: not available
NewJFrame(Window).pack() line: not available
NewJFrame(Window).initGUI() line 334

It started happening after I made some simple changes. I then tried to run the version from yesterday that was working but incredibly that fails too.

MyEclipse is using JDK compliance 5.0

Your help will be greatly appreciated,

Alejandro Barrero
 
Alejandro Barrero
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For clarity, this is the code that creates the panel with card layout:

The problem happens with pack();
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that is where the problem occurs? Please run the code unchanged from the command line and make sure to get line numbers on your stack trace. An ArrayOutOfBoundsIndex is usually caused by calling the wrong index, or a badly-written "for" loop.
 
Alejandro Barrero
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am sure that is where the problem occurs. I put a break at the line with the pack() command and the problem occurs when the command is executed. If I don't add anything to the panel with the card layout there is no problem.
You are correct that array index out of bounds is strange because the CardLayout uses a vector to store the components. The exception is happening on a JViewport trying to execute trying to execute getComponent() with argument 0. I have used card layout many times in the pass and this code was working till early this morning.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A breakpoint doesn't necessarily mean that is the origin of the exception; it might only mean that is where it appears in your code.
Still strange that you are getting an Exception, but remember: Vector stores its elements in an array, so it might throw an out of bounds exception. There are in fact 11 places in the Vector API documents where it declares an ArrayIndexOutOfBoundsException.

Try debugging with the step-into function only (it might work the f5 key) and try running the app from the command line to find out where the Exception actually occurs. Actually a try-catch with ex.printStackTrace() might be a quicker way to find where the Exception arose.
 
Alejandro Barrero
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unbelievable, but the problem was with the MyEclipse work space. Everything works fine when I move the code to a new work space.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alejandro Barrero:
Unbelievable, but the problem was with the MyEclipse work space. Everything works fine when I move the code to a new work space.
How strange. Has anybody else had such a problem with MyEclipse? I have never used it myself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!