• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

First time javaFXML

 
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, guys, I'm trying to get this program to work I got a text file it will read in and then it will cycle through the array list of riddle and give one at a time the user answers it to see if they get it right. For now, I'm just trying to get it to display the riddle and check to see if the answer is right. I'm using Java scene builder I'm just now playing with it.So I'm lost on a lot of it but from what I have seen and read I don't understand why this doesn't work.

This is the Controller



This is the FXML Document

which is where I get an error line 20



This is the start stage



Any help would be great id like to learn to put graphics with my code.

 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I don't understand why this doesn't work.


Please TellTheDetails (that's a link), don't just say it doesn't work.  What should the program do?  What isn't it doing?  Are you getting an error?  If so, what is the full error message?
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry i thought i did put te error in there im getting an error on line 20 in the fxml file its says something about it not being in the root
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code probably isn't what you want.  Look at the while condition.
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the one should be an i So it should be while i is less than 5. The reason i have that is cause i only wana give them five riddles than ask if they wanna play again

 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:what is the full error message?

 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Stallard wrote:the one should be an i So it should be while i is less than 5. The reason i have that is cause i only wana give them five riddles than ask if they wanna play again


How about
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
true i could do that didnt think about it that way but i did get rid of that error but now im having an issue with when i try to get the label to display the riddle it has a null value and not the string.The string is a sting up til i try to put it in the givenriddle variable then it turns to null and blows up
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my updated code

The Controller:



my riddle class


i used the simp;e string property casue thought it may work but it dont.Least i dont see where it has chaged anything so i may put the Riddle and Answer var back to a string
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are thinking that the variables rr and ra turn into null between lines 39 and 40?  Try putting a System.out.println in, maybe after line 37, like this: I think you'll find this prints "null" because Riddle and Answer aren't set in the class Riddle.
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed my riddle class
so now
if i do a system.out.print(rr) i get the riddle but givenriddle.setText still blows up.
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Stallard wrote:... but givenriddle.setText still blows up.


*sigh*  Please post the full error text.  I can't do anything with "still blows up."
 
Daniel Stallard
Ranch Hand
Posts: 90
Java ME MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my error i get when i run it it prints the riddle in the ide and the answer

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: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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 dstallardriddlemeup.DStallardRiddleMeUp.start(DStallardRiddleMeUp.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 dstallardriddlemeup.DStallardRiddleMeUp
I:\MyFiles\Programing\Classes\ITP-220 Java 2\Assignments\Project\dStallardRiddleMeUp\nbproject\build-impl.xml:1052: The following error occurred while executing this line:
I:\MyFiles\Programing\Classes\ITP-220 Java 2\Assignments\Project\dStallardRiddleMeUp\nbproject\build-impl.xml:806: Java returned: 1
BUILD FAILED (total time: 1 second)
 
Rancher
Posts: 259
13
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that first of all you should make a copy of this project and then rip out everything in there except for the main and start methods and the fxml file. You need to see if the fxml file is even being loaded up. Look at this line here:

Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));



Is that really what your fxml file is named? Is it in a subfolder of the package? it needs a relative path if it is.
Also I didn't see the controller being set in the fxml file in your first anchorpane which is the root of your scene.
And why are you using SimpleStringProperty and not String? Do you have any reason not to use String?
A hello world project is much more appropriate for first time fxml, without the added complexity of a fxml controller or other stuff in it.
 
S Fox
Rancher
Posts: 259
13
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to add that I recently spent 3 whole days trying various implementations of TableView trying to make it work, only to find out that my controller wasn't set up properly. I had no indication that the controller wasn't working, not until I tried making a button and it didn't do anything hahaha. So I ripped everything out and added it back piece by piece until I found the culprit. Another problem I ran into when I started javafx was when extending application you have to make the class Public, and if you don't do it you get a show stopping compile error that mentions mirroring but the real reason isn't very apparent.
 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting from scratch is a good policy when you're stuck.  Still, I think we may be close to a solution to the problem.

Launch SceneBuilder and open your FXML file.  Click on the "That's My Answer" to highlight it.  In the right hand accordion menu, click on "code".

In the OnAction text field, you have "answerButtonAction" as the method to execute, but you don't have a controller designated yet.  For now, just remove "answerButtonAction" from OnAction, save and execute your main program again.  Got a GUI to display?  Good.  (If not, post the problem and don't continue.)

Assuming you have gotten your GUI to display, now try adding a controller to the FXML.  In SceneBuilder, on the left hand accordion menu, click "Controller".  Add your controller class.  Now you can add back the "answerButtonAction" as the method.
 
I once met a man from Nantucket. He had a tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic