ImageView doesn't work in JavaFX

后端 未结 1 722
傲寒
傲寒 2021-01-26 12:28

not just this, other codes have the same problem. just can\'t use ImageView.

Environment : macOS, IntelliJ

Caused by: java.lang.IllegalArgumentException: Invalid

1条回答
  •  执笔经年
    2021-01-26 12:40

    The Image constructor takes a url as a parameter. If you don't put a protocol in it, then it assumes that the item comes off of the classpath. Obviously, /Users/fangyuan/Desktop/PIC.png won't be in your classpath.

    To read from a file instead of the classpath, then stick the file:// protocol in front of the path you want to read:

    file:///Users/fangyuan/Desktop/PIC.png
    

    Or

    Paths.get("/Users/fangyuan/Desktop/PIC.png").toUri().toString()
    

    which would output the same thing.

    0 讨论(0)
提交回复
热议问题