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?