• 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

Timer exception when adding shapes

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I am having an issue with a exception when trying to add new shapes to my JavaFx program. I have a randomizer that will randomly create a new Box object, which is converted to a rectangle for JavaFx use by a method I wrote, which all works fine. But when I setup the timer everything will run perfectly fine the first time through but then fails when it gets to this line when the timer kicks in. This is what the entire method looks like.



Here is using a timer to call the generateShapes method every 2 seconds or so.(As you notice I have a while loop that is commented out, which works perfectly fine but I need a timer which is causing the Thread exception.


If you need more information then let me know.
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrap the contents of your run method in Platform.runLater to put it on the JavaFX Application thread. Or remove the Timer and replace it with a Timeline.
 
Casey Clayton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Damien Smith wrote:Wrap the contents of your run method in Platform.runLater to put it on the JavaFX Application thread. Or remove the Timer and replace it with a Timeline.



Ok so I switched the method over to this but it's saying "void" type not allowed here, what am I doing wrong?

 
John Damien Smith
Rancher
Posts: 387
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to stick with a timer, see this StackOverflow answer on timers and JavaFX:


Though, I'd still be inclined to prefer a Timeline based approach as outlined in Tomas's answer to the same question:
reply
    Bookmark Topic Watch Topic
  • New Topic