【发布时间】:2016-08-27 21:00:35
【问题描述】:
我收到错误消息:“从内部类引用的局部变量必须是最终的或有效的最终”
这个错误指的是:
MyTreeItem LeftRootItem = (MyTreeItem) treeViewLeft.getRoot();
我的错误是什么。为什么这个错误与“treeViewRight”不相似?
addAttribute.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
TreeView treeViewLeft = new TreeView ();
treeViewLeft.setShowRoot(false);
treeViewLeft.setRoot(new MyTreeItem ("root"));
treeViewLeft.getRoot().setExpanded(true);
TreeView treeViewRight;
Button button = new Button ("<<");
HBox hBox = new HBox ();
DBConnect.dbconnect();
treeViewRight = DB.loadAttributeClasses();
treeViewLeft = DB.getAttributesfromClassorProduct(selectedItem.getClassID());
treeViewRight.setShowRoot(false);
treeViewRight.getRoot().setExpanded(true);
hBox.getChildren().addAll(treeViewLeft, button, treeViewRight);
Scene scene = new Scene(hBox);
Stage attributeSelect = new Stage ();
attributeSelect.setTitle("Hello World!");
attributeSelect.setScene(scene);
attributeSelect.show();
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
MyTreeItem rightItem = (MyTreeItem) treeViewRight.getSelectionModel().getSelectedItem();
DB.setProdClassAttr(selectedItem.getClassID(), rightItem.getClassID(), selectedItem.getType());
rightItem.getParent().getChildren().remove(rightItem);
MyTreeItem LeftRootItem = (MyTreeItem) treeViewLeft.getRoot();
}
});
}
});
【问题讨论】: