在Jar

时间:2015-06-21 21:24:34

标签: java javafx fxml scene

我的程序在Netbeans中运行完美。当我尝试执行jar时,只加载主页面。当您尝试进行转换时,程序会挂起并提供classdefnotfoundexception。当我尝试加载新的fxml时,似乎会出现此问题。

这是我的主要课程。

主类 - 启动代码

public void start(Stage primaryStage) throws Exception 
{

    stage = primaryStage;


    splashScreen();

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

splashScreen方法

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方法,用于启动挂起发生的转换。

@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();
    }
  }

}

两种playvid方法都是一样的。他们只是播放不同的视频。但 这是playvid方法。

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);
    }
}

最后,切换fxml文件的replaceSceneContent方法。

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();
}

值得注意的另一件事是我加载视频文件的方式。我不确定这是否是问题,但我使用这种方法。

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

对于任何感兴趣的人,fxml文件

<?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>

这是出现的堆栈错误。

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 个答案:

没有答案