从javafx 2.2迁移到javafx 8期间,我遇到了一些问题; Javafx 8不支持静态@FXML元素。
我有以下情况(代码已简化):
家长控制器:
public abstract class ParentController implements Initializable {
@FXML
protected Label parentLabel;
@Override
public void initialize(URL location, ResourceBundle resources) {
// do smth
}
}
儿童控制器(不仅有一个孩子):
public class ChildController extends ParentController {
@Override
public void initialize(URL location, ResourceBundle resources) {
super.initialize(location, resources);
parentLabel.setText("text");
}
}
在此代码的先前版本中,parentLabel是静态的,并且工作正常。 但是现在我在标签上尝试setText时遇到了NullPointerException。
我正在寻找这种情况下最简单的解决方案。
UPD 1。
child fxml:
<AnchorPane id="" fx:id="apDentalClinics" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="590.0" prefWidth="1200.0" style="" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="com.package.ChildController">
<children>
//Something here, except our lable
</children>
</AnchorPane>