imageio.IIOException: Can't read input file

前端 未结 3 1275
鱼传尺愫
鱼传尺愫 2020-12-06 00:31

I\'ve started Java a week ago, and now I would like to insert an image into my window. Whatever I try I keep having this in Eclipse: javax.imageio.IIOException: Can\

3条回答
  •  执笔经年
    2020-12-06 01:07

    Have you tried using new File("logo.jpg"); (without the leading /)?

    And are you sure, the logo.jpg is copied to your output? (Some IDEs don't copy every file from your source-directories to your output (or target) directories.)

    /src
    |-> Window.java
    |-> Logo.jpg
    

    becomes

    /out
    |-> Window.class
    

    (Note that the IDE/compiler does not copy the image to your output-directory and so the compiled code cannot find the image - allthough you did specify the correct path)

提交回复
热议问题