0

I have fairly complicated program which we are suppose to modify.

Here we a MainWindow which wraps around the components of the application and display them as UI.

MainWindow.java:

// Independent Ui parts residing in this Ui container
private BrowserPanel browserPanel;
..
@FXML
private StackPane browserPlaceholder;
..
void fillInnerParts(){
  browserPanel = new BrowserPanel(logic.selectedPersonProperty());
  browserPlaceholder.getChildren().add(browserPanel.getRoot());
  ..
}

BrowserPanel.java:

 /**
 * The Browser Panel of the App.
 */
public class BrowserPanel extends UiPart<Region> {

   ..

    private static final String FXML = "BrowserPanel.fxml";

    @FXML
    private WebView browser;

    public BrowserPanel(ObservableValue<Person> selectedPerson) {
        super(FXML);
        ..  
    }
 ..

BrowserPanel.fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.web.WebView?>

<StackPane xmlns:fx="http://javafx.com/fxml/1">
  <WebView fx:id="browser"/>
</StackPane>

I tried modifying this Browser class to display an image instead.

MainWindow.java

// Independent Ui parts residing in this Ui container
private ImagePanel imagePanel;
..
@FXML
private StackPane ImagePanelPlaceholder;
..
void fillInnerParts(){
  imagePanel = new ImagePanel();
  imagePanelPlaceholder.getChildren().add(imagePanel.getRoot());
  ..
}

ImagePanel.java

public class ImagePanel extends UiPart<Region>{
    private static final String FXML = "ImagePanel.fxml";

    @FXML
    private ImageView imageView;

    public ImagePanel(){
        super(FXML);
        Image sample = new Image("/images/sample.png");
        imageView.setImage(sample);
    }
}

ImagePanel.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.ImageView?>


<ImageView fx:id="imageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" />

However, I am getting the error:

SEVERE: Fatal error during initializing nullnull
java.lang.NullPointerException
    at seedu.address.ui.MainWindow.fillInnerParts(MainWindow.java:120)

where fillInnerParts is the method to add all components into the MainWindow as shown above.

How would I go about modifying this such that I can display a picture on my JavaFX application?

Carrein
  • 3,231
  • 7
  • 36
  • 77
  • And what is on line 120 of `MainWindow.java`? – Zephyr Feb 28 '19 at 16:48
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Zephyr Feb 28 '19 at 16:49
  • Add `System.out.println(imagePanelPlaceholder);` to the beginning of your fillInnerParts method, to verify that imagePanelPlaceholder is not null. – VGR Feb 28 '19 at 16:50
  • @Zephyr Line 120 is `imagePanelPlaceholder.getChildren().add(imagePanel.getRoot());` and yes @VGR, it prints `null` - I am not sure how am I implementing this view wrongly though. – Carrein Feb 28 '19 at 17:13

0 Answers0