Loading new FXML in a Jar

329 views Asked by At

My program runs flawlessly in Netbeans. When I try to execute the jar, only the main page loads. When you try to do a transition, the program hangs and gives a classdefnotfoundexception. This issue seems to occur when I'm trying to load new fxml.

This is my main class.

Main Class - Startup code

public void start(Stage primaryStage) throws Exception 
{

    stage = primaryStage;


    splashScreen();

    stage.setFullScreenExitKeyCombination(NO_MATCH);
    stage.setFullScreen(true);
    primaryStage.show();
}

splashScreen method

public void splashScreen()
{
    try {
        FXMLDocumentController splash = (FXMLDocumentController) replaceSceneContent("FXMLDocument.fxml");
        splash.setApp(this);
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

FXMLDocument Method that starts the transition where the hanging happens.

@FXML
private void handleButtonAction(KeyEvent event) throws IOException, Exception 
{

    if(event.getCode() == KeyCode.A)
  {

    Random randomGenerator = new Random();
    int randomInt = randomGenerator.nextInt(100);
    if(randomInt % 2 > 0)
    {
        application.playVid();
    }
    else
    {
        application.playVid1();
    }
  }

}

Both playvid methods are the same. They just play different videos. But here is the playvid method.

public void playVid() throws IOException 
{
    try {
        FXMLVideoController eatingVid = (FXMLVideoController) replaceSceneContent("FXMLVideo.fxml");
        eatingVid.setApp(this);
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

Finally, the replaceSceneContent method that switches out fxml files.

private Initializable replaceSceneContent(String fxml) throws Exception              {
    FXMLLoader loader = new FXMLLoader();
    InputStream in = FeedingStationV5.class.getResourceAsStream(fxml);
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setLocation(FeedingStationV5.class.getResource(fxml));
    AnchorPane page;
    try {
        page = (AnchorPane) loader.load(in);
    } finally {
        in.close();
    } 
    Scene scene = new Scene(page);
    stage.setScene(scene);
    stage.setFullScreenExitKeyCombination(NO_MATCH);
    stage.setFullScreen(true);
    stage.sizeToScene();
    return (Initializable) loader.getController();
}

The other thing thats worth noting is the way I load my video files. I'm not sure if that is the issue but I use this method.

File eatingVid = new File("src/feeding/station/v5/eating.mp4");
Media eatingV = new Media(eatingVid.toURI().toString());
MediaPlayer eating = new MediaPlayer(eatingV);

For anyone who is interested, the fxml file

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.media.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="feeding.station.v5.FXMLVideoController">
   <children>
      <MediaView fx:id="mediaView" />

   </children>
</AnchorPane>

Here is the Stack error that comes up.

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1770)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1653)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3965)
at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3911)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2502)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$349(GlassViewEventHandler.java:228)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$121/1305255490.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)
at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
at com.sun.glass.ui.View.notifyKey(View.java:956)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1765)
    ... 27 more
Caused by: java.lang.NoClassDefFoundError: com/sun/javaws/Main
    at feeding.station.v5.FeedingStationV5.playVid1(FeedingStationV5.java:80)
    at feeding.station.v5.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:87)
    ... 37 more
Caused by: java.lang.ClassNotFoundException: com.sun.javaws.Main
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 39 more
0

There are 0 answers