2013-04-21 53 views
0

我試圖用我的擴展版本替換標準TreeView時出現此異常,以簡化我創建一個簡單項目的過程。當然有一個簡單的解決方案。當我嘗試更換標準TreeView時發生異常

例外:

Can not set testtreeviewwithitems.MyTestTree field testtreeviewwithitems.Sample.treeView to javafx.scene.control.TreeView 
/C:/Users/Vlad/Documents/NetBeansProjects/TestTreeViewWithITems/build/classes/testtreeviewwithitems/Sample.fxml:10 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) 
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) 
    at java.lang.reflect.Field.set(Field.java:680) 
    at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:659) 
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:572) 
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2694) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2683) 
    at testtreeviewwithitems.TestTreeViewWithITems.start(TestTreeViewWithITems.java:25) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29) 
    at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:67) 
    at java.lang.Thread.run(Thread.java:722) 

Sample.java:

package testtreeviewwithitems; 

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 

public class Sample implements Initializable { 

@FXML 
private MyTestTree taskTreeView = new MyTestTree(); 

@Override 
public void initialize(URL url, ResourceBundle rb) { 
} 

} 

TestTreeView.java:

package testtreeviewwithitems; 

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



public class TestTreeView extends Application { 

    public static void main(String[] args) { 
    Application.launch(TestTreeView.class, args); 
    } 

    @Override 
    public void start(Stage stage) throws Exception { 
     Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); 

     stage.setScene(new Scene(root)); 
     stage.show(); 
    } 
} 

MyTestTree.java:

package testtreeviewwithitems; 

import javafx.scene.control.TreeView; 

public class MyTestTree extends TreeView { 

} 

Sample.fxml:

<?xml version="1.0" encoding="UTF-8"?> 

<?import java.lang.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<AnchorPane id="AnchorPane" prefHeight="200.0" prefWidth="320.0" xmlns:fx="http://javafx.com/fxml"  fx:controller="testtreeviewwithitems.Sample"> 
    <children> 
    <TreeView fx:id="treeView" editable="true" focusTraversable="false" layoutY="0" prefHeight="50.0" prefWidth="100.0" showRoot="false" /> 

    </children> 
</AnchorPane> 

的Java -vesion:

java version "1.7.0_11" 
Java(TM) SE Runtime Environment (build 1.7.0_11-b21) 
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode) 

更新:看來我已經找到了解決辦法,以後我會後回答。

回答

相關問題