0
@FXML
private TableColumn<Backup, Image>columnSucces;

 columnSuccess.setCellValueFactory(new PropertyValueFactory<Backup, Image>("image"));
columnSucces.setCellFactory(new Callback<TableColumn<Backup, Image>, TableCell<Backup,Image>>(){

                @Override
                public TableCell<Backup, Image> call(TableColumn<Backup, Image> arg0) {
                     final ImageView imageview = new ImageView();
                        imageview.setFitHeight(50);
                        imageview.setFitWidth(50);

                        //Set up the Table
                        TableCell<Backup, Image> cell = new TableCell<Backup, Image>() {
                            public void updateItem(Backup item, boolean empty) {
                                if (item != null) {
                                    imageview.setImage(new Image("x-mark-small.png"));
                                }               
                                }
                        };

                cell.setGraphic(imageView);
                return cell;
            }
            });

I got nullpointerexception error when i am trying to add an image into a column for a table view. I cant understand where is my problem.

@edit. I have solved nullpointerexception, but now my image does not appear in the table column. I received an warning that my updateItem method is never used.

CobianuA
  • 15
  • 5
  • I know what is nullpointerexception, stay calm.My problem is that i dont understand why i am getting this error on my code. I have no explanation. – CobianuA Aug 22 '16 at 09:08
  • Are you sure that you have instantiated "columnSucess"? Please post an [MCVE](http://stackoverflow.com/help/mcve) reproducing the problem as well as the stack trace to your `NullPointerException`. This will make it much easier to help you. – Jonatan Stenbacka Aug 22 '16 at 09:13
  • This is a duplicatr of the question linked above however, unless you can explain why you expect not to get a NPE in that line (obviously you seem tho thing `columnSucces` is not `null`) and provide enough information to find the issue (which you haven't done here. Neither do we know, how/where this variable is declared, nor do we know how you hope to set it's value.) – fabian Aug 22 '16 at 09:14
  • First. **you always need to invoke the super method when you override `updateItem`**. This is done by adding `super(item, empty)` inside the method body. This might not be causing the issue though. As for your issue, try loading the image like this instead: `new Image(Images.class.getResource([INSERT URL HERE]).toExternalForm())`; – Jonatan Stenbacka Aug 22 '16 at 10:17
  • I dont understand where i need to add the super(item, empty) and the new Image(Images.class.getResource([INSERT URL HERE]).toExternalForm()) doesnt work too – CobianuA Aug 22 '16 at 11:33
  • See also: [How to populate a tableview cell with an image ... in JavaFX?](http://stackoverflow.com/questions/35883984/how-to-populate-a-tableview-cell-with-an-image-from-sqlite-database-in-javafx) This is a closer duplicate question, but alas I can't modify my duplicate vote to match the better duplicate question. – jewelsea Aug 22 '16 at 22:53

0 Answers0