Image does not appear after Gero o . jar

Asked

Viewed 973 times

0

How do I get my image to appear in the application after the . jar generation? I’m doing it this way and it’s not working.

@FXML
private ImageView image;
@Override
public void initialize(URL url, ResourceBundle rb) {
    File file = new File("src/icons/logo-superplano.png");
     Image imagem = new Image(file.toURI().toString());
     image.setImage(imagem);
}
  • 2

    Take a look at this question. http://answall.com/questions/15574/addir-imagem-ao-jar/15719#15719

  • The image is already inside a package. And when I use Image image2 = new Image(frmLoginController.class.getResourceAsStream("/src/icons/logo-superplano.png")); of error.

  • Put the mistake there.

  • Exception in Application start method
java.lang.reflect.InvocationTargetException

  • When you try the way you are in the question, the same error occurs?

  • No, the image appears when I compile and run the program. However when the . jar image does not appear

Show 1 more comment

2 answers

1


I solved the problem by placing the image in the same package as the main class. And then I used this code:

Image imagem = new Image(getClass().getResourceAsStream("logo-superplano.png"));

0

I opened the jar with Winrar and copy file or folder and just drag the file or folder to Winrar

  • I don’t understand....

  • open the . jar with Winrar and then drag the files or folder into the Winrar that it copies the files or folder into the . jar

  • Dragging which folders into Winrar? Because my image is already inside the package.

  • The icons folder. The compiler only puts sources files inside a jar and no images you have to manually copy the images

  • The icons folder is already inside the jar. When I open by Winrar it is already there.

  • With the images?

  • As I said I put the image inside a package with the name icons. I believe that when I create a package it is already inside src

  • Yes, with the image

  • Try this File file = new File("classpath:icons/logo-superplano.png");

  • The image does not appear

Show 5 more comments

Browser other questions tagged

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