Forums Register Login

compile errors in Java FX

+Pie Number of slices to send: Send
I have to recreate a previous project using Java FX, but am unsure as to where to actually code this thing. Our instructor told us that as long as we use the same component names for the fxid for each component, we should be able to recycle the code. I needed a little help with that past assignment, so rather than re-post all of that code I'll simply link to that post: Joes Automotive

*Note* I eventually got all of the bugs worked out of that previous code, so that's not a problem. The code displayed there only has a few minor changes compared to the final edit. I just thought it would be better to post the URL rather than flood this post with all of that code.

I've already used Scene Builder to set up the GUI with all of the components, named all of the fxid for each component so that they were the same as the components in the previous assignment, and made a controller class that I connected in the Scene Builder program's Controller Class option

Here's what I have so far:

FXJoesAuto.java



FXJoesAutoController.java


The exit button by itself worked fine, it's connected to the On Action thing in the Scene Builder program, but the clear button is giving me a ton of errors when I try to compile the Controller class with it. I'm not sure where to Frankenstein this stuff together.


FXJoesAutoController.java:77: error: <identifier> expected
vaccumCar.setSelected(true);
^
FXJoesAutoController.java:77: error: illegal start of type
vaccumCar.setSelected(true);
^
FXJoesAutoController.java:78: error: <identifier> expected
washCar.setSelected(false);
^
FXJoesAutoController.java:78: error: illegal start of type
washCar.setSelected(false);
^

...etc and so on....

20 errors



I got the top portion of the code for the controller from View > Show Sample Controller Skeleton > Copy

The problems I'm having with this code, is that I'm not sure why the clear button won't work, but beyond that I'm not sure where to begin to start stuffing the rest of the code from the aforementioned project (see URL link above) into this this.
+Pie Number of slices to send: Send
Nothing to do with FX.

Your line 77 has a statement inside a class (the inner class) but not inside a method. You are not allowed statements outside methods/constructors/initialisers.
+Pie Number of slices to send: Send




This still gives me a list of errors. I'm confused on classes within classes. Until recently, all of our classes were created in other files, so putting it all in one thing like this is throwing me off. It compiles, but won't run. I have no idea what all this means.

Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: Error resolving onAction='#clear', either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/kr4ckl3s/Documents/Java%20Programs/FXJoesAutomotive.fxml:15

at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.access$100(Unknown Source)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at FXJoesAuto.start(FXJoesAuto.java:11)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application FXJoesAuto


+Pie Number of slices to send: Send
What does your FXML look like around where you define the clear button?

That exception looks like a mapping issue, possibly.
+Pie Number of slices to send: Send
There are some sample for Controller Method Event Handlers in the "Introduction to FXML" document, try following that pattern (your implementation can't be checked by somebody in this forum without provided source).

https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#controller_method_event_handlers

Just copy and pasting from that source:

A controller method event handler is specified by a leading hash symbol followed by the name of the handler method. For example:


Note the use of the fx:controller attribute on the root element. This attribute is used to associate a controller class with the document. If MyController is defined as follows:

package com.foo;


the handleButtonAction() will be called when the user presses the button, and the text "You clicked me!" will be written to the console.

In general, a handler method should conform to the signature of a standard event handler; that is, it should take a single argument of a type that extends javafx.event.Event and should return void (similar to an event delegate in C#). The event argument often carries important and useful information about the nature of the event; however, it is optional and may be omitted if desired. So this is also a valid handler:

 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4000 times.
Similar Threads
How to load same main fxml file multiple times by clicking on the new tab button?
Dynamic Shapes in FXML
Modify the root node of subscene from different class
JavaFx tableview mouse scroll bug
Take user input in TextField, display in ListView
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:26:57.