Forum Stats

  • 3,838,710 Users
  • 2,262,394 Discussions
  • 7,900,739 Comments

Discussions

JavaFX, Urgent compilation errors!

Caique
Caique Member Posts: 1
edited May 25, 2017 11:34AM in JavaFX 2.0 and Later

Hello everyone, I need an urgent help, I'm doing a JavaFX course, and in it we have to do a calculator using Scene Builder, I was able to do everything that was requested, but when I put it to onAction, when generating the execution method Button, in XML it appears with a "#", example: onAction = "# onClickNumeros", and I believe that for this reason Netbeans is not compiling the code, nor even finding the method in the control file.

On the lines that have the "#" appears the following message: "The controller is not defined in the root component", I'm already searching for three days to solve this, I need a lot of help with this to be able to evolve in the course

Thanks so much if anyone can help me !!

This is the code:

FXML:

image

Controller:

/*
* 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 {

<span class="hljs-meta">@FXML</span> <span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNumZero; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum1; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum2; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum3; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum4; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum5; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum6; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum7; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum8; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> Button btnNum9; <br/><span class="hljs-keyword" style="font-weight: bold;">private</span> TextField txtVisor;     <br/><span class="hljs-meta"><br/>@FXML</span> <span class="hljs-function"><span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">void</span> <span class="hljs-title" style="color: #990000; font-weight: bold;">onClickNumeros</span><span class="hljs-params">(ActionEvent event)</span> </span>{ <br/>Button btnNumerico = ((Button)event.getTarget());  <br/>String _id = btnNumerico.getId();  <br/><span class="hljs-keyword" style="font-weight: bold;">switch</span>(_id){ <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNumZero"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"0"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum1"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"1"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum2"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"2"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum3"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"3"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum4"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"4"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum5"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"5"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum6"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"6"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum7"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"7"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum8"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"8"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>; <br/><span class="hljs-keyword" style="font-weight: bold;">case</span> <span class="hljs-string" style="color: #dd1144;">"btnNum9"</span>: txtVisor.appendText(<span class="hljs-string" style="color: #dd1144;">"9"</span>); <span class="hljs-keyword" style="font-weight: bold;">break</span>;       } }  <br/><span class="hljs-meta"><br/><br/>@Override</span> <span class="hljs-function"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-keyword" style="font-weight: bold;">void</span> <span class="hljs-title" style="color: #990000; font-weight: bold;">initialize</span><span class="hljs-params">(URL url, ResourceBundle rb)</span> </span>{ <br/><span class="hljs-comment" style="color: #999988; font-style: italic;">// TODO</span> <br/>}

}

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 {

<span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-keyword" style="font-weight: bold;">void</span> <span class="hljs-title" style="color: #990000; font-weight: bold;">start</span><span class="hljs-params">(Stage stage)</span> <br/><span class="hljs-keyword" style="font-weight: bold;"><br/>throws</span> Exception </span>{ <br/>Parent root = FXMLLoader.load(getClass().getResource(<span class="hljs-string" style="color: #dd1144;">"cenaCalculadoraFX.fxml"</span>));  <br/>Scene scene = <span class="hljs-keyword" style="font-weight: bold;">new</span> Scene(root);  stage.setScene(scene); <br/>stage.show(); <br/>}  <span class="hljs-comment" style="color: #999988; font-style: italic;">/** * <span class="hljs-doctag">@param</span> args the command line arguments */</span> <br/><span class="hljs-function"><span class="hljs-keyword" style="font-weight: bold;"><br/>public</span> <span class="hljs-keyword" style="font-weight: bold;">static</span> <span class="hljs-keyword" style="font-weight: bold;">void</span> <span class="hljs-title" style="color: #990000; font-weight: bold;">main</span><span class="hljs-params">(String[] args)</span> </span>{ launch(args); }

}

Compiler Errors Output:

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 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 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<span class="hljs-variable" style="color: teal;">$100</span>(FXMLLoader.java:103) at javafx.fxml.FXMLLoader<span class="hljs-variable" style="color: teal;">$Element</span>.getControllerMethodHandle(FXMLLoader.java:557) at javafx.fxml.FXMLLoader<span class="hljs-variable" style="color: teal;">$Element</span>.processEventHandlerAttributes(FXMLLoader.java:599) at javafx.fxml.FXMLLoader<span class="hljs-variable" style="color: teal;">$ValueElement</span>.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<span class="hljs-variable" style="color: teal;">$launchApplication1</span><span class="hljs-variable" style="color: teal;">$162</span>(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda<span class="hljs-variable" style="color: teal;">$runAndWait</span><span class="hljs-variable" style="color: teal;">$175</span>(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda<span class="hljs-variable" style="color: teal;">$null</span><span class="hljs-variable" style="color: teal;">$173</span>(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda<span class="hljs-variable" style="color: teal;">$runLater</span><span class="hljs-variable" style="color: teal;">$174</span>(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher<span class="hljs-variable" style="color: teal;">$Future</span>.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.W<span class="hljs-keyword" style="font-weight: bold;">in</span>Application._runLoop(Native Method) at com.sun.glass.ui.win.W<span class="hljs-keyword" style="font-weight: bold;">in</span>Application.lambda<span class="hljs-variable" style="color: teal;">$null</span><span class="hljs-variable" style="color: teal;">$148</span>(W<span class="hljs-keyword" style="font-weight: bold;">in</span>Application.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)

Tagged:

Answers

This discussion has been closed.