When I am setting data to the ObservableList
it throwing null pointer exception, I could not understand the problem. anyone please help me to find the solution.
Here is my code:
@FXML
private Label label;
@FXML
private ObservableList<ObservableList> data;
@FXML
private TableColumn column1;
@FXML
private TableColumn column2;
@FXML
private TableView table;
public void initialize(URL url, ResourceBundle rb) {
// TODO
String selectSql = "select first_name,last_name from hr.employees";
try (Connection conn = ConnectDB.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(selectSql)) {
System.out.println("Getting Connection....");
while (rs.next()) {
ObservableList<String> temp = FXCollections.observableArrayList();
temp.add(rs.getString(1));
System.out.println("First Name == "+rs.getString(1));
System.out.println("Last Name == "+rs.getString(2));
temp.add(rs.getString(2));
System.out.println("List Value === "+temp);
data.add(temp);
//table.setItems(temp);
}
table.setItems(data);
} catch (Exception e) {
//System.out.println("Error: "+e.getMessage());
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, e);
}
}
i am getting error in ---> data.add(temp);