Null Pointer Exception Javafx

Asked

Viewed 53 times

0

what’s wrong with the following excerpt from my code ?

public static void retorna(BufferedImage bufImage) throws IOException {
    // String file = new String("test.png");
    // setTfFoto(bufImage);


    Image image = null;
    SwingFXUtils.toFXImage(bufImage, (WritableImage) image);

    //SwingFXUtils.toFXImage(bufImage, image);

    tfFoto.setImage(image);
    System.out.println("imprimiu a foto na tela");

}

tfFoto is an Imageview created using FXML but I can’t in any way receive this Bufferedimage from another way and make it appear in my interface.

Someone could help me ?

  • Which is the line that makes the mistake?

  • I was able to remove the build errors. but the Imageview Called tfFoto I can’t get it to display the image that is passed by parameter by another method that is in another class.

  • If you prefer I can post the whole project on github so you can see it better.

1 answer

0


 Image image = null;
SwingFXUtils.toFXImage(bufImage, (WritableImage) image);

You are trying to cast null for Writableimage. For this to work you need to instantiate/inject Image somehow.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.