This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes viewing from jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "viewing from jtable" Watch "viewing from jtable" New topic
Author

viewing from jtable

egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 30
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
Ranch Hand

Joined: Sep 13, 2007
Posts: 1222

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: 30
i got the TableModel example from a book please what do you suggest i do.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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
How To Ask Questions How To Answer Questions
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 30
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: 19216

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: 30
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: 30
Please help
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Sorry, you're going to have to explain what "removing the throw exception" means and also what code you have now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: viewing from jtable
 
Similar Threads
Drawing graphics with if statement ??
NoClassDefFoundError(unable to open projects)
Array Index outbounds error!? Please help!
Failed to start error in Apache Derby
Tooltip Null Pointer