title: Instantiating a web view media player within a JavaFX application
body: <p>I am writing a piece of educational software, and want the user to be able to select a video to watch from a list that lies within my JavaFX GUI.
  I have created a <code>mediaPlayer</code> class that contains a main method that runs the code and displays the video correctly, 
  however my next task is to instantiate the <code>mediaPlayer</code> class, and pass the URL of the video to be watched as a parameter.</p>
  
  <p>I have attempted to code a <code>MediaPlayerTest</code>, whereby I instantiate the <code>mediaPlayer</code>, pass it a URL as a parameter, and then call the <code>start()</code> method, 
  however I am getting the following errors when running my tester class:</p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
      at javafx.scene.web.WebView.&lt;init&gt;(WebView.java:271)
      at Media.mediaPlayer.start(mediaPlayer.java:34)
      at Media.MediaPlayerTest.main(MediaPlayerTest.java:23)
  Caused by: java.lang.RuntimeException: Internal graphics not initialized yet
      at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
      at com.sun.javafx.webkit.prism.PrismGraphicsManager.&lt;init&gt;(PrismGraphicsManager.java:43)
      at javafx.scene.web.WebEngine.&lt;clinit&gt;(WebEngine.java:290)
      ... 3 more
  </code></pre>
  
  <p>You can find the tester class and <code>mediaPlayer</code> class code below:</p>
  
  <pre><code>public class mediaPlayer extends Application {   
  
      // The url of the video to be played
      String url = "https://www.youtube.com/embed/CySfQY_lgr4";
  
      public mediaPlayer(String url) {
          this.url = url;
      }
  
      @Override 
      public void start(Stage stage) throws Exception {
          WebView webview = new WebView();
          webview.getEngine().load(url);
  
          webview.setPrefSize(640, 390);
          stage.setScene(new Scene(webview));
          stage.show();
      }
  
      public static void main(String[] args) { 
          launch(args);
      }
  
  }
  </code></pre>
  
  <p>And <code>MediaPlayerTest</code> class:</p>
  
  <pre><code>public class MediaPlayerTest {
  
      public static void main (String[] args) {
          try {
              mediaPlayer mp = new mediaPlayer("https://www.youtube.com/embed/CySfQY_lgr4");
              mp.start(null);
          } catch (Exception ex) {
              Logger.getLogger(MediaPlayerTest.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  }
  </code></pre>
  
  <p>Any help for solving this issue would be much appreciated.</p>