Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JavaFX FXML TableView setCellValueFactory with lambda

AD5XJNov 25 2022

I am having a particular problem with my Maven project and getting values from my SQLite3 DAO into a TableView column. I am a complete JavaFX novice so the references to this type problem do not make a solution obvious to me so far.
Any help would be greatly appreciated. Here is snippets of code from the project.
SQLData.java
[code]
public class MyData {
private final IntegerProperty dataid;
public MyData () {
this.dataid = null;
}
// SETTERS AND GETTERS //
public Integer getID() { return dataid.get(); }
public void setID(int intid) { dataid.set(intid); }
}
[/code]

MyDataDAO.java
[code]
ImplMyDataDAO() {
public ResultSet rs;
private String DML;
public ObservableList<QSO> getList() throws SQLException, ClassNotFoundException
{
//Declare a SELECT statement
DML = "SELECT mydata.id as ID;"
//Execute SELECT statement
try
{
ResultSet rsMyData = DBUtil.execQuery(DML); //Get ResultSet from execQuery method
ObservableList<MyData> dataList = getAll(rsMyData); //Send ResultSet to the getAll method and get list object
//Return employee object
return dataList;
}
catch (SQLException e)
{
System.out.println("ImplMyDataDAO::getList 71: select operation has been failed: " + e.getLocalizedMessage());
//Return exception
throw e;
}
finally
{
try
{
DBUtil.close();
}
catch ( SQLException e )
{
System.out.println("ERROR ImplMyDataDAO::getList 87: Error on close(): " + e.getLocalizedMessage());
}
}
}
[/code]
MainWindowController.java
[code]
@FXML private TableView tblLogView;

//defining columns
@FXML private TableColumn<MyData, Number> idCol;
@Override
public void initialize(URL u, ResourceBundle rb )
lstView = FXCollections.observableArrayList();
qso = null;

qsolog = new ImplQsoDAO();  

loadTable();  
try  
{  
  idCol.setCellValueFactory( cellData -> cellData.getValue().getID() );  

}
}
[/code]

The error says:
incompatible types: bad return type in lambda expression
Integer cannot be converted to ObservableValue<Number>
Which to me does not make sense since the getID method should return an integer and I am putting the return value in a cell of type Number ( which to my understanding is proper). Reviewing all the references to tableview, lambda expressions, and ObservableList/ObservableValue have not helped.
So why the requirement of a ObservableValue type and how do I make that conversion to show in the table column?

Comments
Post Details
Added on Nov 25 2022
0 comments
1,071 views