mardi 24 mars 2015

issue with this tutorial:Populate a tableview using database in JavaFX

I get a nullpointerxception when following this tutorial: Populate a tableview using database in JavaFX .


I modified it to make it simpler and fit my needs: Instead of Usermaster, I have Person object.



while(rs.next()){
Person per = new Person();
per.ClientID.set(rs.getInt(1));
per.FirstName.set(rs.getString(2));
per.LastName.set(rs.getString(3));


The code stops at per.ClientID.set(rs.getInt(1)); due to nullpointerxception.


If I make system.out.println(rs.getInt(1)) (or any other column), I get the value... But it appears that I can't pass it to my object per.


All Person object vars are SimpleString/IntergerProperty type, as shown in the tutorial.


Can someone help me to identify the mistake I made in coding this?


Thank you


**Update: need to initialize values.


now stuck with nullpointerexception here:



while(rs.next()){
Person per = new Person();
per.ClientID.set(rs.getInt("CLIENTID"));
per.FirstName.set(rs.getString("FIRSTNAME"));
per.LastName.set(rs.getString("LASTNAME"));

data.add(per);

}
tableview.setItems(data); ---> here

Aucun commentaire:

Enregistrer un commentaire