Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
Greenhorn
Posts: 27
Android C++ Java
  • Mark post as helpful
  • send pies
  • 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!

 
Marshal
Posts: 5988
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 3353
33
  • Mark post as helpful
  • send pies
  • 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: 11
  • Mark post as helpful
  • send pies
  • 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 ...)

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!