[JavaFX] IllegalArgumentException occurs in new Image (path)

(゚ Д ゚ #)

I held my head for about 2 hours, so I posted it as a memorandum. It looks sharp (it looks sharp). JavaFX8. It's a ridiculous story, but I spelled it with a sense of self-discipline, so if you have time, please go out with me. ...... If you are really in trouble and have arrived here, let's dance together (┓ ^ ω ^) ┛)) Nisa Nisa ♪ (┓ ^ ω ^) ┛)) Hisa Hoisa ♪

「IllegalArgumentException: Invalid URL: unknown protocol: c」

If you insert the absolute path as it is, you will be told that you don't know such a protocol. I don't even know this one.

2017-06-06_00h25_14.png

So, if you look closely, you're requesting a URL instead of a path. Even if you don't look closely, the protocol is written, and the first line of the error is also written firmly. On the contrary, he says at the coding stage. Tehepero. 2017-06-06_00h29_42.png

Well, in the end, all you have to do is "specify the local file by URL". When I try to google, it seems that I can just add "file:" to my head.

hoge.java


String path = "C:\\~(Abbreviation)";
Image image = new Image("file:"+path);

That's it. It's hard. Give me back my 2 hours.

bonus

Does anyone say, "I got a'RuntimeException: Internal graphics not initialized yet'when I tested it?" I was vomited. If you look here (http://namihira.hatenablog.com/entry/2014/12/29/125834), I think it will be solved.

Recommended Posts

[JavaFX] IllegalArgumentException occurs in new Image (path)
IllegalArgumentException occurs in PathMatcher :: matches
JavaFX8 image display
Display a loading image in JavaFX and then display another image
What's new in Java 8
What's new in Java 9,10,11