JavaFX TableView/Column Null pointer exception

I am having trouble with Null pointers when trying to initiate Table population. I have my object from class called "Komponenta" which data I put in ObservableList and then try to show it in a TableView. I've tried this time to work with multiple fxml screens and for some reason it doesn't work with more than 1 .fxml. Test is a function that I call when a button is pressed on main.fxml so it loads a new one.

public ObservableList<Komponenta> komponente = FXCollections.observableArrayList(new Komponenta("Neki Tip", "Neki Proizvodac","Neki opis", 5)); @FXML private TableView<Komponenta> Tablica; @FXML private TableColumn<Komponenta,String> Tip; @FXML private TableColumn<Komponenta,String> Proizvodac; @FXML private TableColumn<Komponenta,String> Karakteristika; @FXML private TableColumn<Komponenta,Integer> Komada; @FXML private void test(ActionEvent event) throws IOException{     Node node=(Node) event.getSource();     Stage stage = (Stage) node.getScene().getWindow();     Parent root = (Pane)FXMLLoader.load(getClass().getResource("ElKomponenta.fxml"));     Scene scene = new Scene(root);     stage.setScene(scene);;        } @FXML private void initialize() throws Exception  {     System.out.println(komponente.get(0).getKomada());     Tip.setCellValueFactory(new PropertyValueFactory<Komponenta, String>("tip"));     Proizvodac.setCellValueFactory(new PropertyValueFactory<Komponenta, String>("proizvodac"));     Karakteristika.setCellValueFactory(new PropertyValueFactory<Komponenta, String>("karakteristika"));     Komada.setCellValueFactory(new PropertyValueFactory<Komponenta, Integer>("komada"));     Tablica.setItems(komponente); } 


 <TableView fx:id="Tablica" prefHeight="603.0" prefWidth="889.0">                       <columns>                         <TableColumn fx:id="Tip" prefWidth="177.0" text="Tip" />                         <TableColumn fx:id="Proizvodac" minWidth="0.0" prefWidth="207.0" text="Proizvođač" />                           <TableColumn fx:id="Karakteristika" prefWidth="326.0" text="Karakteristike" />                           <TableColumn fx:id="Komada" minWidth="0.0" prefWidth="178.0" text="Komada" />                       </columns>                     </TableView> 


Caused by: java.lang.NullPointerException at application.MainController.initialize( ... 27 more 

Which is the line that first starts to setCellValueFactory.

Also if needed,

public class Komponenta {  private String proizvodac; private String tip; private String karakteristika; private Integer komada;  public Komponenta(String a, String b, String c, Integer d){     this.tip = a;     this.proizvodac = b;     this.karakteristika = c;     this.komada = d; }  public String getProizvodac() {     return proizvodac; }  public void setProizvodac(String proizvodac) {     this.proizvodac = proizvodac; }  public String getTip() {     return tip; }  public void setTip(String tip) {     this.tip = tip; }  public String getKarakteristika() {     return karakteristika; }  public void setKarakteristika(String karakteristika) {     this.karakteristika = karakteristika; }  public Integer getKomada() {     return komada; }  public void setKomada(Integer komada) {     this.komada = komada; } 



Category: java Time: 2016-07-31 Views: 58

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.252 (s). 12 q(s)