GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

JavaFX, erros de compilação urgente!

Tags: #<Tag:0x00007f0ba618f278> #<Tag:0x00007f0ba618ef08> #<Tag:0x00007f0ba618ecb0>

Olá pessoal, preciso de uma ajuda urgente, estou fazendo um curso de JavaFX, e nele temos que fazer uma calculadora utilizando o Scene Builder, consegui fazer tudo que foi pedido, porem quando vou colocar no onAction, ao gerar o método de de execução do botão, no XML ele aparece com um “#”, exemplo: onAction="#onClickNumeros", e acredito que por esse motivo o Netbeans não está compilando o código, e nem encontrando o método no arquivo de controle.

Nas linhas em que tem o “#” aparece a seguinte mensagem: “O controlador não é definido no componente raiz”, já estou a três dias pesquisando para resolver isso, preciso muito de ajuda com isso para poder evoluir no curso

Agradeço de mais se alguém conseguir me ajuda!!

**FXML** <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.TextField?> <?import javafx.scene.layout.AnchorPane?>

Controlador

/*

  • 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 calculadorafx;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

/**
*

  • @author cteles
    */
    public class cenaCalculadoraFXController implements Initializable {

    @FXML
    private Button btnNumZero;
    private Button btnNum1;
    private Button btnNum2;
    private Button btnNum3;
    private Button btnNum4;
    private Button btnNum5;
    private Button btnNum6;
    private Button btnNum7;
    private Button btnNum8;
    private Button btnNum9;
    private TextField txtVisor;

    @FXML
    private void onClickNumeros(ActionEvent event) {
    Button btnNumerico = ((Button)event.getTarget());

     String _id = btnNumerico.getId();
     
     switch(_id){
         case "btnNumZero": 
             txtVisor.appendText("0");
             break;
         case "btnNum1": 
             txtVisor.appendText("1");
             break;
         case "btnNum2": 
             txtVisor.appendText("2");
             break;             
         case "btnNum3": 
             txtVisor.appendText("3");
             break;
         case "btnNum4": 
             txtVisor.appendText("4");
             break;
         case "btnNum5": 
             txtVisor.appendText("5");
             break;
         case "btnNum6": 
             txtVisor.appendText("6");
             break;
         case "btnNum7": 
             txtVisor.appendText("7");
             break;
         case "btnNum8": 
             txtVisor.appendText("8");
             break;
         case "btnNum9": 
             txtVisor.appendText("9");
             break;        
             
             
             
             
             
             
     } 
    

    }

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

}

Main

/*

  • 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 calculadorafx;

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

/**
*

  • @author cteles
    */
    public class CalculadoraFX extends Application {

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

     Scene scene = new Scene(root);
     
     stage.setScene(scene);
     stage.show();
    

    }

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      launch(args);
      }

}

Saída de erros do compilador

ant -f C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX jfxsa-run
init:
deps-jar:
Created dir: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build
Updating property file: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\built-jar.properties
Created dir: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\classes
Created dir: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\empty
Created dir: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\generated-sources\ap-source-output
Compiling 2 source files to C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\classes
Copying 1 file to C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\build\classes
compile:
Created dir: C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\dist
Detected JavaFX Ant API version 1.3
Launching fx:jar task from C:\Program Files\Java\jdk1.8.0_131\jre…\lib\ant-javafx.jar
Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing.
Please set manifest.custom.codebase property to override the current default non-secure value ‘*’.
Launching fx:deploy task from C:\Program Files\Java\jdk1.8.0_131\jre…\lib\ant-javafx.jar
No base JDK. Package will use system JRE.
No base JDK. Package will use system JRE.
jfx-deployment-script:
jfx-deployment:
jar:
Copying 12 files to C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\dist\run742861444
jfx-project-run:
Executing C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\dist\run742861444\CalculadoraFX.jar using platform C:\Program Files\Java\jdk1.8.0_131\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:748)
Caused by: javafx.fxml.LoadException: No controller specified.
file:/C:/Users/cteles/Documents/NetBeansProjects/CalculadoraFX/dist/run742861444/CalculadoraFX.jar!/calculadorafx/cenaCalculadoraFX.fxml:13

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.getControllerMethodHandle(FXMLLoader.java:557)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:599)
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 calculadorafx.CalculadoraFX.start(CalculadoraFX.java:22)
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 calculadorafx.CalculadoraFX
Java Result: 1
Deleting directory C:\Users\cteles\Documents\NetBeansProjects\CalculadoraFX\dist\run742861444
jfxsa-run:
CONSTRUÍDO COM SUCESSO (tempo total: 19 segundos)

Vc precisa especificar o controller(classe java) no fxml.

Na tag AnchorPane adiciona o atributo: fx:controller=“calculadorafx.cenaCalculadoraFXController”

Nossa @Rodrigo_Void, você salvou minha vida agora em!! muito obrigado mesmo… eu pensei que era bug da IDE do Netbeans, baixei um monte de plug-in.

eu tenho que sempre referenciar no FXML dentro do AnchorPane exemplo: fx:controller=“pacotedoprgrama.classeController”…

muito obrigado mesmo!

Amigo você realmente me salvou, muito obrigado, não tem ideia do quanto me ajudou

1 Curtida