Parse boolean from Access db

Hi, I am trying to parse a boolean in from an access database and here's what happens.

1) When I populate the JTable that I'm using when the form initially loads, the table populates correctly.

2) After I edit information using JTextFields, I submit the query to update, which occurs with no issues

3) I then select all fields within the table using the SAME method as above, it throws the following error.

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String

The line of code its having trouble on is:

public Class getColumnClass(int columnIndex){

return types [columnIndex];

}

NOTE: This code is auto-generated by Netbeans and cannot be modified.

The following is my code which is used to populate the JTable:

publicvoid populateTable()

{

ResultSet newResults;

try{

myDatabase.loadDriver();

newResults = myDatabase.runQuery("SELECT * FROM User","search","null");

int columnID = 1;

int rowID = 0;

while(newResults.next() ==true)

{

while(columnID <= 3)

{

if (columnID == 2)

{

String temp = newResults.getString(columnID);

String output ="";

int i = 1;

while (i <= temp.length())

{

output = output +"*";

i++;

}

tblData.setValueAt(output, rowID, columnID - 1);

columnID++;

}

elseif (columnID == 3)

{

tblData.setValueAt(newResults.getBoolean(3), rowID, columnID - 1);

columnID++;

}

else

{

tblData.setValueAt(newResults.getString(columnID), rowID, columnID - 1);

columnID++;

}

//If all six columns of a row have been filled, move to the next row

}

columnID = 1;

rowID++;

}

}catch (ClassNotFoundException ex){

ex.printStackTrace();

}catch (SQLException ex){

ex.printStackTrace();

}

}

Any ideas? Thanks in advance.

Message was edited by:

bcwolfe

[3409 byte] By [bcwolfea] at [2007-11-27 2:31:14]
# 1
Anyone?
bcwolfea at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 2
You are asserting thatreturn types [columnIndex];is throwing a ClassCastException? That seems unlikely to me. But you're the one looking at the stack trace, not me. Maybe you could post it?
DrClapa at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 3

Certainly. I didn't post it before since it's rather long. Here it is:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String

at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:3614)

at javax.swing.JTable.prepareRenderer(JTable.java:3928)

at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)

at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)

at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)

at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)

at javax.swing.JComponent.paintComponent(JComponent.java:743)

at javax.swing.JComponent.paint(JComponent.java:1006)

at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4972)

at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)

at javax.swing.JComponent._paintImmediately(JComponent.java:4868)

at javax.swing.JComponent.paintImmediately(JComponent.java:4675)

at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String

at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:3614)

at javax.swing.JTable.prepareRenderer(JTable.java:3928)

at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)

at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)

at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)

at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)

at javax.swing.JComponent.paintComponent(JComponent.java:743)

at javax.swing.JComponent.paint(JComponent.java:1006)

at javax.swing.JComponent.paintChildren(JComponent.java:843)

at javax.swing.JComponent.paint(JComponent.java:1015)

at javax.swing.JViewport.paint(JViewport.java:728)

at javax.swing.JComponent.paintChildren(JComponent.java:843)

at javax.swing.JComponent.paint(JComponent.java:1015)

at javax.swing.JComponent.paintChildren(JComponent.java:843)

at javax.swing.JComponent.paint(JComponent.java:1015)

at javax.swing.JComponent.paintChildren(JComponent.java:843)

at javax.swing.JComponent.paint(JComponent.java:1015)

at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)

at javax.swing.JComponent.paintChildren(JComponent.java:843)

at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4979)

at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)

at javax.swing.JComponent.paint(JComponent.java:996)

at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)

at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)

at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)

at java.awt.Container.paint(Container.java:1709)

at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)

at sun.awt.RepaintArea.paint(RepaintArea.java:224)

at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)

at java.awt.Component.dispatchEventImpl(Component.java:4044)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Window.dispatchEventImpl(Window.java:1778)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

bcwolfea at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 4
Okay, I see, so not there at all. But it looks like you have a column that's supposed to contain Boolean objects, and the column has a renderer that matches that, but somehow you tried to put a String into a cell in that column.
DrClapa at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 5

What do you mean "not there at all"? I debugged this code and that's where the error is occurring. The code below is the code I'm using to add the value into the column. Why would this be seen as adding a String and not a Boolean?

else if (columnID == 3)

{

tblData.setValueAt(newResults.getBoolean(3), rowID, columnID - 1);

columnID++;

}

bcwolfea at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 6
?
bcwolfea at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 7

> What do you mean "not there at all"?

Exactly that. The error occurs where the stack trace says it occurs, namely:

at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:3614)

It's easy to see that is not in a method called getColumnClass. In fact it's in a method called getTableCellRendererComponent. And you can see that the method is in an inner class called BooleanRenderer, which suggests to me that its purpose is to render boolean values. And the ClassCastException says the problem is java.lang.String, which tells me that something is trying to cast a String to something that isn't a String. Which is why I said what I said in the last post.

DrClapa at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...
# 8
Ok, well, instead of being sarcastic and arguing about where the error occurred, why don't you tell me something that might help me to fix it?
bcwolfea at 2007-7-12 2:45:51 > top of Java-index,Java Essentials,Java Programming...