I'm in a college, learning Java and one of our projects has asked us to make an image editor (whose controller is called ImageDisplayController
) that has a kernel filter window after a button is pressed (lovingly labeled "Show Filter"). This is done through 2 separate stages, as suggested by my instructors.
However, in trying to get the image in an ImageView (called imageView2
, it keeps returning as a null. I've created an instance of the controller, called mainController
, and gotten imageView2
from there, and then used the getImage()
method to get the image in the ImageView, however it still returns as null. Can someone please show me what I'm doing wrong? Any help is appreciated.
private void applyKernel() {
try {
double sum = 0;
for (int j = 0; j < 9; j++) {
sum += Double.parseDouble(textFields()[j]);
}
for (int i = 0; i < 9; i++) {
double textNum = Double.parseDouble(textFields()[i]);
textNum /= sum;
kernel[i] = textNum;
}
//Part Where There's Trouble
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ImageDisplay.fxml"));
ImageDisplayController mainController = fxmlLoader.getController();
Image image = mainController.imageView2.getImage();
Image newImage = convolve(image, kernel);
mainController.imageView2.setImage(newImage);
} catch (NumberFormatException e) {
System.out.println("That is not a valid number");
} catch (NullPointerException e) {
System.err.println("The image cannot be null");
}
}