• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The program seems to crash when trying to open or save file JavaFX

 
Greenhorn
Posts: 27
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I honestly don't know why the program crash every time I tried to open or save a file using this program.
Can anyone point out the problem?
Thank you!

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say the program's crashing, do you mean it's hanging?  

When opening, you have this code:
When will this loop terminate?
 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I especially have a problem with the readability of your code.
Don't just put everything in your startmethod, JavaFx uses controllers for a reasson.

It's also unclear to me, why you're opening a file in three different locations.

This is an exampe of a program that let's you open, edit and save a textfile.
For this example I maded the file and the list containing the files static, in production you would find a cleaner solution for that:


MainClass:


The BaseController:


The EditController:


sample.fxml:


center.fxml:


As you can see, when you try to edit a file an textarea is loaded in the center of the borderpane containing the text of the file.
After editing the file is overwritten.
For this example you can only edit the file you last loaded, Ideally you would have a way to choose which file you want to edit.

A final tip. I myself am a big fan of seperating the desing of your fxml file from your businesslogic, ergo your fxmlfile should contain all your design.
If you don't know how to edit a fxmlfile, use scenebuilder, which you can download here or most idea's (like netbeans, intelij and eclipse) have build in plugin's.
Removing the desing from your controller (or in your case your startmethod) will greatly improve your readability.
 
ShinRyu Kazuto
Greenhorn
Posts: 27
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So when I tried to run the program you shown me, it gave me this error message:
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$154(LauncherImpl.java:182)


what does it mean? Does it mean that it could not load the .fxml file?

Sorry for the beginner question. I haven't got into learning much about JavaFX design.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ShinRyu Kazuto wrote:So when I tried to run the program you shown me, it gave me this error message:



You shouldn't get any errors when running my code as you can see on this demo:

 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've put my source code on git for you.
Keep in mind that it's not productioncode, it's ment to be a quick example, but it should help you get started.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the program crash every time


Please copy the full text of the error message and paste it here.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ShinRyu Kazuto,

Please take a look at this code it´s more easier but dont crashed and you can read a text-file and show it (I think it ...)

 
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic