• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nullpointer exeception from a JTable.getModel()

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again! I'm still working on my database application. I want to output the rows in my database table in a JTable, but the getModel() function returns a nullpointerexception. I know that this means the value returned is empty/null. I just don't know how to fix it. Here is the testfunction to add a row:

The variable siteTable is declared like this:


Thanks in advance!
 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did simple program with same way you did, it adds values in JTable properly. Did you initialize siteTable an object of JTable ?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Which line do you suffer the Exception on? That will enable you to work out whether siteTable or the returned model is equal to null.
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Which line do you suffer the Exception on? That will enable you to work out whether siteTable or the returned model is equal to null.


Line 2 in the code part I submitted.
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Welcome to the Ranch  

Thanks!
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Mesman wrote:
Line 2 in the code part I submitted.



That means siteTable is null.
As Ganish asked, where have you initialised it?
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've made the table with the Netbeans pallete Swing controls.
It is declared, but a value is never asigned to the variable siteTable. I can enter rows in it with a GUI editor and that works while the variable is still empty (I tested it with a JOptionPane  with siteTable in it). It is declared like this:

So there is some sort of value, but no string or something "tangible".
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it to work somehow. I placed the function after the variable was initialised. Thanks for the help, and see you at the next problem! :p
 
Ganish Patil
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Mesman wrote:I got it to work somehow. I placed the function after the variable was initialised. Thanks for the help, and see you at the next problem! :p

You are most welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic