Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:23:26+00:00 2026-06-15T14:23:26+00:00

I am relativly new to java and honestly to programing. I am working on

  • 0

I am relativly new to java and honestly to programing. I am working on a little tool. One of the functionalites is a pseudo-ftp-client showing the content on ftp hosts, also allowing to switch between the different folders. For the file/folder Listing i am using a TableView. Now I wanted to tune the visual stuff and ad some graphics to the cell depending on its content if it is a file or a folder. But when I use the following code in my CellFactory, it sets the Graphic not only on the cell fullfilling the statement, further when scrolling the TableView up and down, the graphic appears on different cells randomly and after a few seconds it crashes.

    public BorderPane addFTPBorderPane(){

    ftpBorderpane = new BorderPane();
    ftpBorderpane.setPadding(new Insets(0));
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10));
    grid.setHgap(20);
    grid.setId("simplebluegradient");
    Button getFTPButton = new Button("Verbinden");
    grid.add(getFTPButton, 1, 0);
    ftpBorderpane.setTop(grid);

    VBox vbox = new VBox();
    final TableView<MyFTPFile> ftpTable = new TableView<MyFTPFile>();

    Callback<TableColumn<MyFTPFile,String>, TableCell<MyFTPFile,String>> cellFactory =
            new Callback<TableColumn<MyFTPFile,String>, TableCell<MyFTPFile,String>>() {
                public TableCell<MyFTPFile,String> call(TableColumn<MyFTPFile,String> p) {
                    cell = new TableCell<MyFTPFile, String>() {
                        @Override
                        public void updateItem(String item, boolean empty) {
                            super.updateItem(item, empty);
                            setText(item);
                            if(item.equals("test")){
                                Image folderIcon = new Image(imagesPath+"folder.png");
                                setGraphic(new ImageView(folderIcon));
                            }

                        }

                    };

                    cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                            if (event.getClickCount() > 1) {
                                cell = (TableCell<MyFTPFile,String>) event.getSource();
                                System.out.println(cell.getTableRow().getItem());
                                try {
                                    MyFTPClient.getInstance().changeFTPdir(cell.getTableRow().getItem());
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                ftpObservablelist = MyFTPClient.getInstance().getFtpObservableList(); 
                                ftpTable.setItems(ftpObservablelist);

                            }
                        }
                    });

                    return cell;
                }
            };


    ftpTable.setEditable(true);

    TableColumn<MyFTPFile,String> nameColumn = new TableColumn<MyFTPFile,String>("Dateiname");
    nameColumn.setMinWidth(200);
    nameColumn.setCellFactory(cellFactory);
    nameColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("name"));

    TableColumn<MyFTPFile,String> sizeColumn = new TableColumn<MyFTPFile,String>("Grösse");
    sizeColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("size"));

    TableColumn<MyFTPFile,String> dateColumn = new TableColumn<MyFTPFile,String>("Änderungsdatum");
    dateColumn.setMinWidth(140);
    dateColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("date"));

    TableColumn<MyFTPFile,String> rightsColumn = new TableColumn<MyFTPFile,String>("Berechtigungen");
    rightsColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("rights"));

    TableColumn<MyFTPFile,String> userColumn = new TableColumn<MyFTPFile,String>("User");
    userColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("owner"));

    TableColumn<MyFTPFile,String> groupColumn = new TableColumn<MyFTPFile,String>("Group");
    groupColumn.setCellValueFactory(new PropertyValueFactory<MyFTPFile,String>("group"));

    ftpTable.getColumns().addAll(nameColumn,sizeColumn, dateColumn, rightsColumn, userColumn, groupColumn);

    vbox.getChildren().add(ftpTable);
    ftpBorderpane.setCenter(vbox);

    getFTPButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e){
            try {
                MyFTPClient.getInstance().doConnection(kunde);
                MyFTPClient.getInstance().reqFTPdir();


            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            ftpObservablelist = MyFTPClient.getInstance().getFtpObservableList(); 
            ftpTable.setItems(ftpObservablelist);


        }   
    });



    return ftpBorderpane;       

}

The following Error appears when it crashes:

java.lang.NullPointerException
at ch.trusted.java.hcst.gui.GuiTest$19$1.updateItem(GuiTest.java:972)
at ch.trusted.java.hcst.gui.GuiTest$19$1.updateItem(GuiTest.java:1)
at javafx.scene.control.TableCell.updateItem(TableCell.java:539)
at javafx.scene.control.TableCell.indexChanged(TableCell.java:105)
at javafx.scene.control.TableCell$1.invalidated(TableCell.java:93)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:195)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:161)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:130)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:163)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:112)
at com.sun.javafx.scene.control.skin.TableRowSkin.updateCells(TableRowSkin.java:251)
at com.sun.javafx.scene.control.skin.TableRowSkin.doUpdateCheck(TableRowSkin.java:151)
at com.sun.javafx.scene.control.skin.TableRowSkin.layoutChildren(TableRowSkin.java:157)
at javafx.scene.Parent.layout(Parent.java:1018)
at com.sun.javafx.scene.control.skin.TableRowSkin.handleControlPropertyChanged(TableRowSkin.java:110)
at com.sun.javafx.scene.control.skin.SkinBase$3.changed(SkinBase.java:282)
at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:107)
at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:196)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:123)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
at javafx.scene.control.Cell.setItem(Cell.java:333)
at javafx.scene.control.Cell.updateItem(Cell.java:557)
at javafx.scene.control.TableRow.updateItem(TableRow.java:246)
at javafx.scene.control.TableRow.indexChanged(TableRow.java:92)
at javafx.scene.control.TableRow$1.invalidated(TableRow.java:85)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:195)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:161)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:130)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:163)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:112)
at com.sun.javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1596)
at com.sun.javafx.scene.control.skin.VirtualFlow.addLeadingCells(VirtualFlow.java:1049)
at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1005)
at javafx.scene.Parent.layout(Parent.java:1018)
at javafx.scene.Scene.layoutDirtyRoots(Scene.java:513)
at javafx.scene.Scene.doLayoutPass(Scene.java:484)
at javafx.scene.Scene.access$3900(Scene.java:169)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2199)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)

If I just remove the if statement including the setGraphic out it works and no crashes appear.

Any Idea what the problem is here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:23:27+00:00Added an answer on June 15, 2026 at 2:23 pm

    Item can be null (for instance in an empty cell).

    Write:

    if (item != null && item.equals("test")) 
    

    Or another way to do the test because the constant string will never be null nor equal null:

    if ("test".equals(item))  
    

    There may be other errors in your code, but that one seemed obvious on a quick review.

    You might also be interested in the custom cell factory for row based processing in this question. It is very well written.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relativly new to Java, and especially to swing. I develop with Netbeans
I'm a relatively new Java programmer and I'm having difficuly removing more than one
I'm relatively new to Java, so I have little to no idea where to
I'm relatively new to Java and I'm still trying to understand the fundamentals. I
I'm still relatively new to Java and Android development, so I'm still unfamiliar with
I'm relatively new to Java and would appreciate any help on this! I have
Like lots of askers on SO, I'm relatively new to java and have attempted
I am relatively new to Objective-C and I am coming from a Java background,
Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could
I am relatively new to PHP, but experienced Java programmer in complex enterprise environments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.