1

メニュー項目でメニューを作成するのに問題があります。

このチュートリアル ( http://docs.oracle.com/javafx/2/ui_controls/menu_controls.htm ) に従っていましたが、実行すると nullpointer エラーが発生します。私のコードは次のようになります。

@Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {

    ventas.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            FXMLLoader ventasloader;
            ventasloader = new FXMLLoader(getClass().getResource("VentasGUI.fxml"));
            Stage ventasstage = new Stage();
            AnchorPane ventas = null;
            try {
                ventas = (AnchorPane) ventasloader.load();
            } catch (IOException ex) {
                Logger.getLogger(PuntoDeVentaController.class.getName()).log(Level.SEVERE, null, ex);
            }
            Scene ventasscene = new Scene(ventas);
            ventasstage.setScene(ventasscene);
            ventasstage.setTitle("Venta");

            VentasGUIController controller = ventasloader.<VentasGUIController>getController();
            controller.setUser(userID);

            ventasstage.show();
        }

...しかし、NetBeans が自動的に追加するスケルトン コードだけを残しても、次のようになります。

@Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {

    ventas.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

...「まだサポートされていません」を取得するのではなく、nullpointerexception を取得します。http://docs.oracle.com/javafx/2/api/javafx/scene/control/MenuItem.htmlのドキュメントを見ましたが、イベント ハンドラーが空であることがわかりません。チュートリアルと同じ。

私が間違っていることを知っている人はいますか?

ありがとう!

4

1 に答える 1