2015-06-20 127 views
1

我试图用黑色背景创建一个非常简单的VBox。就这样。没有其他的。我用FXML来形容我的VBox加载FXML时发生javafx.fxml.LoadException

sample.fxml:

<?xml version="1.0" encoding="UTF-8"?> 
<?import javafx.scene.layout.VBox?> 

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="sample.Controller" alignment="CENTER" background="#000000ff"> 
</VBox> 

Controller.java:

package sample; 

public class Controller { 
    // No code written. Not required. 
} 

Main.java:

package sample; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 


/* Code auto generated by IDEA IDE. */ 
public class Main extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception{ 
     Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); 
     primaryStage.setTitle("Adi's login app"); 
     primaryStage.setScene(new Scene(root, 300, 275)); 
     primaryStage.show(); 
    } 


    public static void main(String[] args) { 
     launch(args); 
    } 
} 

我使用IDEA IntelliJ IDE。而且我收到以下错误:

Exception in Application start method 
 
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method 
 
\t at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 
 
\t at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182) 
 
\t at com.sun.javafx.application.LauncherImpl$$Lambda$2/51228289.run(Unknown Source) 
 
\t at java.lang.Thread.run(Thread.java:745) 
 
Caused by: javafx.fxml.LoadException: 
 
/Users/aditya/Desktop/workspace/Java/LoginApp/out/production/LoginApp/sample/sample.fxml:5 
 

 
\t at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108) 
 
\t at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101) 
 
\t at sample.Main.start(Main.java:13) 
 
\t at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863) 
 
\t at com.sun.javafx.application.LauncherImpl$$Lambda$53/87719178.run(Unknown Source) 
 
\t at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326) 
 
\t at com.sun.javafx.application.PlatformImpl$$Lambda$49/2001689116.run(Unknown Source) 
 
\t at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295) 
 
\t at com.sun.javafx.application.PlatformImpl$$Lambda$51/779320874.run(Unknown Source) 
 
\t at java.security.AccessController.doPrivileged(Native Method) 
 
\t at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294) 
 
\t at com.sun.javafx.application.PlatformImpl$$Lambda$50/1474675095.run(Unknown Source) 
 
\t at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 
 
Caused by: java.lang.IllegalArgumentException: Unable to coerce #000000ff to class javafx.scene.layout.Background. 
 
\t at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:495) 
 
\t at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258) 
 
\t at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54) 
 
\t at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:508) 
 
\t at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:359) 
 
\t at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:321) 
 
\t at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:231) 
 
\t at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:763) 
 
\t at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827) 
 
\t at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536) 
 
\t ... 18 more

这究竟是为什么?请让我知道,如果我犯了任何错误,或者我错过了任何东西。

回答

0

与Intellij无关,我也有这个问题。 我正在编译Java 1.8,我改为1.7并且可以工作。