This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes tablemodel getcolumnclass() method produces null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "tablemodel getcolumnclass() method produces null pointer exception" Watch "tablemodel getcolumnclass() method produces null pointer exception" New topic
Author

tablemodel getcolumnclass() method produces null pointer exception

Simon Knight
Greenhorn

Joined: Mar 04, 2004
Posts: 25
Hi - i'm trying to load results from an oracle database into a JTable with a button in each row. Unfortunately, I'm having some difficulty with the getColumnClass which I understand is supposed to tell the JTable how to render the data contained in the column, which in this instance should be JButtons. The code below compiles ok:



but when the tablemodel is used in the JTable like



or like



running the main class results in a null pointer exception - thus:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at dbforensicanalysistool.SQLTableModel.getColumnClass(SQLTableModel.java:74)


I can't work out why!!?? Can anyone help?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

You are getting the null pointer because the value Object returned by getValueAt is null. I have encountered this problem before, though I have not been able to figure out why it is caused.

This is the workaround:


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Simon Knight
Greenhorn

Joined: Mar 04, 2004
Posts: 25
You are a lifesaver - thankyou!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tablemodel getcolumnclass() method produces null pointer exception
 
Similar Threads
Help with using JCheckBox in JTable to return a value in another column
Images in a JTable
JTable Dynamic - Urgent
How do I get selected rows that have a check against them using check boxes in a table
jtable not displayed