找不到Javafx图像

时间:2017-11-16 10:35:40

标签: java javafx

我的JavaFX代码中有这段代码

Image arrowRight = new Image("/Users/murad/Desktop/arrowright.png");
ImageView arrowRightv = new ImageView(arrowRight);

我的目标是找到桌面上的图片,然后将其放在屏幕上。但是此代码会返回此错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62
)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherIm
pl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:
328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62
)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java
:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Launche
rImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c
    at javafx.scene.image.Image.validateUrl(Image.java:1121)
    at javafx.scene.image.Image.<init>(Image.java:620)
    at Kanban.start(Kanban.java:152)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Launch
erImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.j
ava:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:29
5)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.jav
a:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java
:95)
Caused by: java.net.MalformedURLException: unknown protocol: c
    at java.net.URL.<init>(URL.java:600)
    at java.net.URL.<init>(URL.java:490)
    at java.net.URL.<init>(URL.java:439)
    at javafx.scene.image.Image.validateUrl(Image.java:1115)
    ... 8 more

我尝试用FileInputStream做我上面所做的事情,但那不起作用。我也从Mac获得了网址,所以这绝对不错。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

参数是一个网址

"file:/Users/murad/Desktop/arrowright.png"

错误显示您在Windows上使用“c:/ ....” - 因此出现没有协议c的错误。 ( “文件:/// C:/ ...”)。