Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception that I cannot track  RSS feed

 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi very new to posting questions int this forum

I am from a non technical background so please dont mind any newbie questions:

Please help with the following exception

Exception in thread "AWT-EventQueue-3" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:447)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:650)
at javax.swing.JTable.getValueAt(JTable.java:2715)
at javax.swing.JTable.prepareRenderer(JTable.java:5715)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2108)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2010)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1806)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
at javax.swing.JComponent.paintComponent(JComponent.java:765)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JViewport.paint(JViewport.java:764)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:581)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:866)
at javax.swing.JComponent.paint(JComponent.java:1038)


@Code:
[Added code tags - see UseCodeTags for details]
cheers!!



 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ajith,
Welcome to the Ranch!

If you see at the top of the trace, it provides you with an idea of what the issue is. You are trying to access the first row in an empty Vector.

I think you have not pasted the complete exception trace. Please do so. Usually, that will point to a line number in your code from where the issue originated.
In the trace that you have posted, the line numbers shown are all of internal Java classes. From this, I am guessing that you are using a JTable and are trying to read the table contents - whereas, the table is empty and you get this exception.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that your table model has a problem. My guess is that you're using a Vector to store the data for the model, but its getRowCount() method fails to return the actual number of rows in that Vector.

You didn't post the code for your table model, but that's where I would suggest you should look next.
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranganathan,
Thank you

The exception I posted is on an eclipse from ubuntu OS. Some one told me that it is better to view SWING components on a windows OS, so when tried to run the same code in Windows & eclipse I got the below and as you have asked, even on ubuntu there was no line number specified in the exception printed in the console.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at javax.swing.RepaintManager$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1000(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

and I coped the entire code. As suggested I am no where else modifying the table.

Cheers,
Ajith
 
Randall Twede
Ranch Hand
Posts: 4683
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not exactly answering the question, but using an IDE does have the advantage that you can copy and paste the exception trace. i can't do that using the command prompt.

this is the first time i have seen a trace that does not include a line of my code. that is how i usually find the problem.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:not exactly answering the question, but using an IDE does have the advantage that you can copy and paste the exception trace. i can't do that using the command prompt.

Yes you can. On Windows, click the icon on the left of the title bar. Tale a look at what's under the 'Edit' menu.

I'm sure Linux must have something too.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajith, does your code respect Swing's single threaded rule? Are all Swing methods and constructors invoked on the EDT?
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bruke

Thanks for the tip and

What I am confident of is that I did not use any threads in my code, but either ways, how do I make sure that all the methods(Swing methods) are called in EDT.

cheers,
Ajith
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using SwingUtilities#invokeLater(...).

I recommend this tutorial: Concurrency in Swing.
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bruke, yes I verified that all the methods are being invoked on EDT by using "javax.swing.SwingUtilities.isEventDispatchThread()".

It always returned true while the control was in each of the methods. So I believe that all the methods are invoked on EDT.

but still the same exception.

any further help please

cheers,
Ajith
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You stand a better chance of getting help if you share your SSCCE (<-link In case you are not aware of what it means, please do click on the link to find out)
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SSCCE:

The tasks at hand are to "remove all the components of the Jinternal Frame", "add a specific number of columns" and then "add rows" to the Jtable.
so I have 3 methods.

1. setNewContainers()
2. insertColumns()
3. insertRows()


private void removeAll() {

table = null;
internalFrame.getContentPane().removeAll();
internalFrame.validate();

table = new JTable(0,0);
JScrollPane scrollPane = new JScrollPane(table);

internalFrame.getContentPane().add(scrollPane);

internalFrame.validate();


}

private void insertColumns() {

//add columns to the column model of the table
for(int i=0;i<totalColumns;i++){
table.getColumnModel().addColumn(new TableColumn());
}
}

private void insertRows(){

String[] rowData = getRowData();
((DefaultTableModel)table.getModel()).addRow(rowData);

}

and that is it. These methods are called when I select a Tree node i.e a Tree selection event

am I doing some thing wrong???
so any help.......please
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry thats not SSCCE. One of the S is for "Self contained" which means code we can copy to our machine and compile. Did you even bother to check the link? If not please do so. http://sscce.org/
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And do go through this link too -> UseCodeTags
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Maneesh,
let me get back.

cheers
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Maneesh and Bruke

please find the SSCCE.

I have compiled the below code and its producing the same exception as in my original code.
so please take a look.



I could not create a more shorter version of my code. But from my next posts I will try.

Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you also the post and add the stack trace (Using code tags) which you get on running the code you posted?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, that code does not respect Swing's single threaded rule. The constructor of your class Strange, which extends JFrame, is invoked on the main Thread -- not on the EDT. You really need to go through the Concurrency tutorial I linked to earlier.

However, that's not the cause of the Exception. I've tracked down that adding the columns directly to the table's ColumnModel isn't adding them to the TableModel. Since the TableModel still has a columnCount of 0, there's an index out of bounds condition when adding the row.

You may have uncovered an obscure bug in Swing; these bug reports have stack traces quite similar to yours:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4515236
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4089573
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh thanks Bruke,

For the SSCCE it happened that the call is from main thread, but in my code I am sure that I am following the rule.

Thanks for identifying my mistake.

cheers
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My findings coincide with Darryl. I provided this simple model to your existing code.

It works (as in no exception), but like Darryl said, the new row values are not reflected.
You can see it in action by changing the getRowData() to


Was this code for academic purposes or are you using it for some real application.
If yes, consider a custom table model which uses a List of data objects internally instead of the vector. The override the required methods to get it working
Typically
getRowCount
getColumnCount
getColumnClass
getColumnName
getValueAt

I am going by memory here and might have missed out on some
 
Ajith Veera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Maneesh,

and I got over the problem. FYI it is for an academic assignment.

cheers
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl's findings are correct. Glad to know that your problem is solved.

And, this is no way related to Ubuntu or Windows...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!