wood burning stoves 2.0*
The moose likes JDBC and the fly likes viewing from jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "viewing from jtable" Watch "viewing from jtable" New topic
Author

viewing from jtable

egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 43
how do i view files with jtable been recieving an error here is the code.

and here is the errorrun:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sm.main.TableModel.getColumnCount(TableModel.java:50)
at javax.swing.JTable.createDefaultColumnsFromModel(JTable.java:1290)
at javax.swing.JTable.tableChanged(JTable.java:4389)
at javax.swing.JTable.setModel(JTable.java:3691)
at javax.swing.JTable.<init>(JTable.java:633)
at javax.swing.JTable.<init>(JTable.java:574)
at sm.main.moviemethod.view(moviemethod.java:110)
at sm.main.movie$2.actionPerformed(movie.java:69)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD STOPPED (total time: 36 seconds)

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1958
    
    7

So you are trying to use a TableModel to get the columns/rows in the database table?

From you error print stack, it looks like "line 50" of your class got a NullPointerException. And I reckon it's the ResutlMetaData variable rmd is null.

How are you getting the necessary info for your meta data?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 43
i got the TableModel example from a book please what do you suggest i do.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Did you call setQuery before applying the model to a JTable? Did this method throw an exception you ignored?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 43
I used the setQuery method in an ActionListener overide method, so when a user presses a button it will bring up the table contents of that button. Or should i declare an inner class from the button?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Well, you currently set the table model before it's properly initialized. You should check not only if there is a database connection, but also if the result set meta data is set. You also shouldn't throw an exception if that occurs because you'll just replace your NullPointerExceptions with other ones. Instead return some defaults - 0 rows, 0 columns, null for getColumnClass and getValueAt.
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 43
The error has stopped showing after removing the throw exception. But an empty frame opens with no values in it or GUI objects in it
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 43
Please help
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

Sorry, you're going to have to explain what "removing the throw exception" means and also what code you have now.
 
Consider Paul's rocket mass heater.
 
subject: viewing from jtable
 
Similar Threads
NoClassDefFoundError(unable to open projects)
Tooltip Null Pointer
Drawing graphics with if statement ??
Array Index outbounds error!? Please help!
Failed to start error in Apache Derby