Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JavaFX Coding problems

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question JavaFX Coding problems

    Hi,

    The code snippet below is a simple program to play an audio song file. The MP3 file is located in the same folder as this code. It compiles without any errors. But when I run the code it gives me two "java.lang.IllegalStateException: Toolkit not initialized" exceptions. Below is full output of excepetion error:

    Exception in thread "Thread-0" java.lang.IllegalStateException: Toolkit not initialized
    at com.sun.javafx.application.PlatformImpl.runLater(U nknown Source)
    at com.sun.javafx.application.PlatformImpl.runLater(U nknown Source)
    at javafx.application.Platform.runLater(Unknown Source)
    at javafx.scene.media.Media$_MetadataListener.onMetad ata(Unknown Source)
    at com.sun.media.jfxmediaimpl.MetadataParserImpl.done (Unknown Source)
    at com.sun.media.jfxmediaimpl.platform.java.ID3Metada taParser.parse(Unknown Source)
    at com.sun.media.jfxmediaimpl.MetadataParserImpl.run( Unknown Source)
    Exception in thread "main" java.lang.IllegalStateException: Toolkit not initialized
    at com.sun.javafx.application.PlatformImpl.runLater(U nknown Source)
    at com.sun.javafx.application.PlatformImpl.runLater(U nknown Source)
    at javafx.application.Platform.runLater(Unknown Source)
    at javafx.scene.media.MediaPlayer.init(Unknown Source)
    at javafx.scene.media.MediaPlayer.<init>(Unknown Source)

    //import necessary packages
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import java.io.*;
     
    public class PlaySong 
    {
    	public static void main(String args[])
    	{
    		String song = new File("song.mp3").toURI().toString();
    		Media audio =null;
    		audio = new Media(song);
    		MediaPlayer mediaPlayer = new MediaPlayer(audio);
    		mediaPlayer.play();
    	}
    }

    Can anyone identify the problem? Iv'e been looking everywhere for solutions, no luck.

    Thanks and much appreciated.


  2. #2
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: JavaFX Coding problems

    Apparently JavaFX initialization won't automatically get triggered by running MediaPlayer.

    Try instantiating JFXPanel in your code:
    JFXPanel fxPanel = new JFXPanel();

  3. The Following User Says Thank You to Starstreak For This Useful Post:

    dougie1809 (March 16th, 2013)

  4. #3
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: JavaFX Coding problems

    Wow it was as simple as creating that object, it worked like a charm.

    Thanks a lot, much appreciated

Similar Threads

  1. from java to javaFX
    By johagood in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 8th, 2012, 02:38 PM
  2. JavaFX on javaprogrammingforums
    By cselic in forum Forum Updates & Feedback
    Replies: 1
    Last Post: July 31st, 2012, 03:48 PM
  3. Replies: 2
    Last Post: February 19th, 2012, 06:36 AM
  4. Questions about javafx
    By mDennis10 in forum Java Theory & Questions
    Replies: 3
    Last Post: September 5th, 2011, 12:19 AM
  5. [SOLVED] JavaFx
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 28th, 2009, 09:13 PM