I bet you used Java FX with Swing, hence you ended up with this problem. Sure, the tutorial leads developers into thinking that the class has to inherit Application in order to launch Java FX applications or put them in a JFXPanel container if they want to use it hand in hand with Swing.

In my case, I used Swing to open a modal Java FX window. When my code executed Platform.runLater(), that error came out.

It took me some time to figure out the solution to set up a Java FX toolkit environment in order to run Java FX applications without having to use a class that inherits Application or integrate a Stage container into the JFXPanel.

The quick solution to setting up the Java FX toolkit is to instantiate JFXPanel without even using it. Just instantiate it and then you can use Platform.runLater().

Here is a sample code.

I came upon this problem because the site I wanted to access had server problems, meaning the website was down. When my code tried to access it again, it gave out this “Invalid use of SingleClientConnManager: connection still allocated” exception message.

My code uses Apache’s HttpClient 3rd party library and I thought at first calling the consumeContent() method of the HttpEntity class did the trick since I never even closed the InputStream when getting a reference to it. It did not.

Luckily, after much surfing I stumbled upon Jason Hudgin’s site where he created a convenience method that avoids this problem.

Rather than using Java’s static Thread.sleep method and calculating how many seconds you need to pass to its parameter, a simple class called TimeUnit simplifies its usage according to hours, minutes and seconds. You can use it using either of the following …

The sample above will run every hour, every 10 minutes and every 30 seconds. Pretty simple and much less tedious right?

Related Posts Plugin for WordPress, Blogger...