Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"AWT-EventQueue-0" java.util.NoSuchElementException: Vector Enumeration

843806Nov 7 2007 — edited Nov 8 2007
I have JDK6 with SwingWorker Thread updating a JScrollPane
myTable extends AbstractTableModel
jtable = Jtable (myTable)
JScrollpane (jtable)

Result set from JDBC queries does Vector.addElement followed by fireTableChanged. Code is below.

Any idea to fix below exception that comes on stdout - it does not show any culprit lines in application code though. The GUI seems to work though the every 2-sec refresh is shaky on screen.

Exception in thread "AWT-EventQueue-
0" java.util.NoSuchElementException: Vector Enumeration
at java.util.Vector$1.nextElement(Vector.java:306)
at javax.swing.plaf.basic.BasicTableHeaderUI.getPreferredSize(BasicTable
HeaderUI.java:746)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1607)
at javax.swing.ViewportLayout.preferredLayoutSize(ViewportLayout.java:78
)
at java.awt.Container.preferredSize(Container.java:1576)
at java.awt.Container.getPreferredSize(Container.java:1561)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1609)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:70
2)
at java.awt.Container.layout(Container.java:1419)
at java.awt.Container.doLayout(Container.java:1408)
at java.awt.Container.validateTree(Container.java:1491)
at java.awt.Container.validate(Container.java:1466)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.j
ava:626)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:127)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:598)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


class myclass extends JFrame /* implements ItemListener */ {

static RsetTable qtm2;

String url ;
public static myTask bgdperf;
public static String query_pf = ...;

public myclass() {
super("Performance Check Frame");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(350, 150);

JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(2,1));

qtm2 = new RsetTable();
JTable table2 = new JTable(qtm2);
table2.setPreferredScrollableViewportSize(new Dimension(320, 250));
JScrollPane scrollpane2 = new JScrollPane(table2);
qtm2.initDB(url,true);

bgdperf = new myTask( );
bgdperf.execute();

JButton jb2 = new JButton("foo1");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
qtm2.doQuery(query_pf);
}
});
p2.add(jb2);
getContentPane().add(p2, BorderLayout.NORTH);
getContentPane().add(scrollpane2, BorderLayout.CENTER);
}


class myTask extends SwingWorker<Object, Object> {
long tskcount = 0;
protected Object doInBackground() {
PreparedStatement ps;
int retval = 0;
while (!isCancelled()) {
try {
Thread.sleep(100); // sleep 1 seconds
qtm2.doQuery(query_pf); // do query
synchronized (this) {
tskcount ++;
}
} catch (InterruptedException e) {
//Cancelled!
return null;
}
publish(tskcount);
}
return null;
}

protected void process(Object cnt) {
// System.out.println("done loop count = " + cnt);
}
}
}

class RsetTable extends AbstractTableModel {
Vector cache; // will hold String[] objects . . .

int colCount;

String[] headers;

Connection db;
PreparedStatement pstmt;

String currentURL;

public RsetTable() {
cache = new Vector(5,5);
new jdbc.driver.xxx
}

public synchronized String getColumnName(int i) {
if (headers.length == 0)
return null;
return headers;
}

public synchronized int getColumnCount() {
return colCount;
}

public synchronized int getRowCount() {
if (cache.isEmpty())
return 0;
else
return cache.size();
}

public synchronized Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}

public synchronized void doQuery(String q) {
cache.removeAllElements();
boolean isPerfcheck;

try {
pstmt = db.prepareStatement(q);


ResultSet rs = pstmt.executeQuery();
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

headers = new String[colCount];
for (int h = 0; h < colCount; h++) {
headers[h] = meta.getColumnName(h+1);
}

while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {

record[i] = rs.getString(i + 1);
// System.out.println("col " + i + ", = " + record[i]);
}


cache.addElement(record);
}
fireTableChanged(null); // notify everyone that we have a new table.

rs.close();
pstmt.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}

public void initDB(String url, boolean perf) {
try {
get connection

} catch (Exception e) {

}
}

public void closeDB() {
try {
// close connection
} catch (Exception e) {

}
}
}



Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2007
Added on Nov 7 2007
4 comments
135 views