• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JavaFx tableview error

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea is to simply populate the table with information from my local database onclick from my "loadData" button. The application runs, but then I get an error in the Controller that indicates a null exception when I press the "Query_1 button. It also appears that the "event" in my loadData ActionEvent method is not being used. Which for the life of me I can't figure out why. Is there a simpler way of doing this? Maybe I have made it too complicated.

Thanks in advance.


UserDetails:




Controller:



Main:



Error message:
https://www.dropbox.com/s/pjaf4gsjokkiujb/error.JPG?dl=0

db setup:
https://www.dropbox.com/home?preview=db_setup.JPG

visual example:
https://www.dropbox.com/home?preview=db.JPG


Thank you,
 
Sheriff
Posts: 6126
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Whenever you mention an error, be sure to include the full error message and stack trace.

I'll take a look at your code in a second.

[Edit: I see you included an image of the error.  It's better to copy and paste directly in the post.]
 
Knute Snortum
Sheriff
Posts: 6126
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first property in UserDetails is "memberId".  You have "MemberId" in line 63 of your Controller.
 
Mike Fowler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for not posting the full error. Here it is.







I also left out the sample.fxml



I appreciate your time.

Thank you,
 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The nullpointer seems to apear because, as knute suggested, you have a capital M on your memberId, but if my memory serves me correctly the table should still be filled, not specifying the correct propertyValueFactory would cause the column to be empty not failling to fill overal. Why do you first set your tableItems to null? By the way you don't need to specify the ObjectClass and variableType in your propetyValueFactory since you already have done while declaring you tableView and columns. Are your sure you're using the correct name of the table and columns as the id in your fxml? fx:id="yourColumnName".
Also you don't need the event, in your fxml add onAction="#yourMethod" to your buttonTag
 
Ranch Hand
Posts: 47
1
IntelliJ IDE Slackware Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me know if you get this working, I'm struggling with a similar situation myself.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it has to do with the try in your loaddataMethod. Create a getObservableList method and seperate the part where you get and loop the resultset to create the obsevableList from your fxmlmethod...
 
Mike Fowler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:The nullpointer seems to apear because, as knute suggested, you have a capital M on your memberId, but if my memory serves me correctly the table should still be filled, not specifying the correct propertyValueFactory would cause the column to be empty not failling to fill overal. Why do you first set your tableItems to null? By the way you don't need to specify the ObjectClass and variableType in your propetyValueFactory since you already have done while declaring you tableView and columns. Are your sure you're using the correct name of the table and columns as the id in your fxml? fx:id="yourColumnName".
Also you don't need the event, in your fxml add onAction="#yourMethod" to your buttonTag



Okay, so I have been toiling with this and I am still getting that null pointer exception. I changed all of my names to match naming convention, so eveything is camel cased. I also removed the object class and variable type from the propertyValueFactory (thanks btw). I set the value to null thinking it would prevent the table from populating on startup, but I was way off. The names for my fxml were in caps which I changed to camel case to match the rest.

Daniel Demesmaecker wrote:I think it has to do with the try in your loaddataMethod. Create a getObservableList method and seperate the part where you get and loop the resultset to create the obsevableList from your fxmlmethod...



Hmm... Okay let me try this and see where I end up. Thank you.
 
Mike Fowler
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I was able to get it working with the suggested changes to my naming convention and made everything camel case.

The second issue was in my loadData Method where I had an unnecessary argument placed inside the parenthesis.



I also changed the cell value factory:



Now aside from alignment issues and the text being white and the background gray. Everything is in order.


Thank you all so very much.
 
Knute Snortum
Sheriff
Posts: 6126
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And thank you for posting your solution back here.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!