我刚刚升级到Ubuntu 15.04,我试图制作一个简单的Labels应用程序作为练习但是我面临来自Java解释器的奇怪错误抱怨。 我确定代码很好,因为它非常简单,这就是为什么我能解决问题,如果有人可以帮我解决这个问题,并且谢谢:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package guis;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
*
* @author ophiel
*/
public class Labeling extends Application{
@Override
public void start(Stage s){
HBox box = new HBox();
ImageView im = new ImageView(new Image("images/lock.png"));
Label lab = new Label("lock\n24 Stages",im);
lab.setContentDisplay(ContentDisplay.BOTTOM);
lab.setStyle("-fx-border:green;-fx-stroke:black;");
Label lab1 = new Label("Circle",new Circle(50,50,50));
lab1.setContentDisplay(ContentDisplay.CENTER);
Label lab2 = new Label("Rectangle",new Rectangle(10,10,40,50));
lab2.setContentDisplay(ContentDisplay.LEFT);
box.getChildren().addAll(lab,lab1,lab2);
s.setScene(new Scene(box,200,200));
s.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
这是解释者的消息:
run:
Exception in Application start method
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:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.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:497)
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$156(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1100)
at javafx.scene.image.Image.<init>(Image.java:608)
at guis.Labeling.start(Labeling.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$50(GtkApplication.java:139)
... 1 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1092)
... 11 more
Exception running application guis.Labeling
Java Result: 1
BUILD SUCCESSFUL (total time: 11 seconds)
我正在运行ubuntu 15.04桌面版我的IDE是netBeans 8.0.2和java版本&#34; 1.8.0_60&#34;
答案 0 :(得分:0)
无法找到图片文件:
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1092)