• Post Reply Bookmark Topic Watch Topic
  • New Topic

Nullpointer exeception from a JTable.getModel()

 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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!
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ?
 
Campbell Ritchie
Marshal
Posts: 52531
119
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Welcome to the Ranch  
Thanks!
 
Dave Tolls
Ranch Hand
Posts: 2271
23
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!