Boa noite, sou novo no forum e com um problema que acho simples (apesar de estar quebrando a cabeça com isso desde as 10h da manhã), em fim, não estou conseguindo colocar eventos no FXML, o caminho para a classe controle está (aparentemente) correto mas mesmo assim não aparece nenhum evento disponível, segue as classes:
Menu:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.URL?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="381.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Configuracao.MenuController">
<stylesheets>
<URL value="@menu.css" />
</stylesheets>
<children>
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="600.0">
<menus>
<Menu mnemonicParsing="false" text="Cadastro">
<items>
<MenuItem mnemonicParsing="false" text="Produto" />
<MenuItem mnemonicParsing="false" text="Cliente" />
<MenuItem onAction="#evtCadCategoria" text="Categoria" /><!-- esse evento não está funcionando :c, fica sublinhado vermelho-->
<MenuItem mnemonicParsing="false" text="Pedido" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Consulta">
<items>
<MenuItem mnemonicParsing="false" text="Produto" />
<MenuItem mnemonicParsing="false" text="Cliente" />
<MenuItem mnemonicParsing="false" text="Descrição" />
<MenuItem mnemonicParsing="false" text="Pedido" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Relatório">
<items>
<MenuItem mnemonicParsing="false" text="Produtos" />
<MenuItem mnemonicParsing="false" text="Cliente" />
<MenuItem mnemonicParsing="false" text="Pedido" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Ajuda">
<items>
<MenuItem mnemonicParsing="false" text="Sobre" />
<MenuItem mnemonicParsing="false" text="Sair" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>
Controle:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Configuracao;
import java.awt.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* FXML Controller class
*
* @author adauc_000
*/
public class MenuController implements Initializable{
/**
* Initializes the controller class.
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
/**
*
* @param event
*/
@FXML
private void evtCadCategoria(ActionEvent event){
try
{
Stage stage=new Stage();
Parent root = FXMLLoader.load(getClass().getResource("CadCategoria.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.showAndWait();
}
catch(Exception e)
{
System.out.println("e");
}
}
}
Erro:
Executing C:\Users\adauc_000\Documents\NetBeansProjects\Trab2B\dist\run1157357557\Trab2B.jar using platform C:\Program Files\Java\jdk1.8.0_72\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: Error resolving onAction='#evtCadCategoria', either the event handler is not in the Namespace or there is an error in the script.
file:/C:/Users/adauc_000/Documents/NetBeansProjects/Trab2B/dist/run1157357557/Trab2B.jar!/Apresentacao/Menu.fxml:20
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at Apresentacao.Trab2B.start(Trab2B.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application Apresentacao.Trab2B
Java Result: 1
Estava tendo um problema parecido antes, o programa não compilava pois o caminha para os controles estava errado, resolvido isso apareceu esse outro problema, essa é a unica tela com eventos no momento.
Desde já, agradeço pela atenção