JavaFx应用程序在具有相同java配置的不同计算机上显示错误

时间:2016-01-01 10:20:38

标签: java eclipse javafx

我使用的是Ubuntu 14.04和Oracle Java 8_45。我已经设置了JAVA_HOME和PATH变量。这是尝试在eclipse上运行的终端输出。 但是,相同的应用程序在具有相同配置的不同机器上运行良好。

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.Utils.getScreen(Utils.java:686)
at com.sun.javafx.webkit.WebPageClientImpl.getScreenBounds(WebPageClientImpl.java:105)
at com.sun.webkit.WCWidget.fwkGetScreenRect(WCWidget.java:118)
at com.sun.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
at com.sun.webkit.network.URLLoader.notifyDidFinishLoading(URLLoader.java:830)
at com.sun.webkit.network.URLLoader.lambda$didFinishLoading$95(URLLoader.java:821)
at com.sun.webkit.network.URLLoader$$Lambda$105/91090058.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$53/146033025.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$52/2027961269.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
at com.sun.glass.ui.gtk.GtkApplication$$Lambda$41/1327763628.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)

这是主类的代码

              import java.awt.SplashScreen;
              import java.util.concurrent.CountDownLatch;

              import javafx.application.Application;
              import javafx.application.Platform;
              import javafx.beans.value.ChangeListener;
              import javafx.beans.value.ObservableValue;
              import javafx.fxml.FXMLLoader;
              import javafx.scene.Parent;
              import javafx.scene.Scene;
              import javafx.scene.image.Image;
              import javafx.stage.Stage;

              public class app extends Application {
             // private Stage primaryStage;
             // private Scene primaryScene;

             @Override
              public void start(Stage stage) {
              try {
              Parent root = FXMLLoader.load(app.class
                .getResource("views/Index.fxml"));
               // default resolution 1000, 730
              Scene scene = new Scene(root, 1000, 710);
              scene.getStylesheets().add("/resource/app.css");
              stage.getIcons().add(
                new Image("/resource/graphics/app_logo.png"));
              stage.setTitle("Opt-app");
              scene.widthProperty().addListener(new ChangeListener<Number>() {
                    @Override
                 public void changed(
                    ObservableValue<? extends Number> observableValue,
                    Number oldSceneWidth, Number newSceneWidth) {

                double screenWidth = Double.parseDouble(newSceneWidth
                        .toString());
                if (screenWidth >= 1000) {
                    Navigation.screenWidth = screenWidth;
                } else {
                    Navigation.screenWidth = 1000;
                }
                Navigation.resizeSceneComponents();

            }
        });
        scene.heightProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(
                    ObservableValue<? extends Number> observableValue,
                    Number oldSceneHeight, Number newSceneHeight) {
                double screenHeight = Double.parseDouble(newSceneHeight
                        .toString());
                // if(screenHeight)
                if (screenHeight >= 710) {
                    Navigation.screenHeight = screenHeight;
                } else {
                    Navigation.screenHeight = 710;
                }
                Navigation.resizeSceneComponents();
            }
        });
        Common.scene = scene;
        Common.mainStage = stage;

        // Get the splashscreen
        final SplashScreen splash = SplashScreen.getSplashScreen();

        // Close splashscreen
        if (splash != null) {
            splash.close();
        }

        stage.setScene(scene);
        stage.show();
    } catch (Exception e) {
        e.printStackTrace();
        Common.print(e);
    }
}

public static void main(String[] args) {
    try {


        Common.print("Starting app...");
        if (SystemConfig.initializingConnection())
                {
            SystemConfig.initCommonProperties();
            Application.launch(app.class, args);
        } else {
            Common.print("app dependency unsatisfied. Please contact to app Team.");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

    }
}

public static void runAndWait(Runnable action) {
    if (action == null)
        throw new NullPointerException("action");

    // run synchronously on JavaFX thread
    if (Platform.isFxApplicationThread()) {
        action.run();
        return;
    }

    // queue on JavaFX thread and wait for completion
    final CountDownLatch doneLatch = new CountDownLatch(1);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            try {
                action.run();
            } finally {
                doneLatch.countDown();
            }
        }
    });

    try {
        doneLatch.await();
    } catch (InterruptedException e) {
        // ignore exception
    }
}

}

0 个答案:

没有答案
相关问题