由基本javafx应用程序

时间:2017-09-15 13:21:37

标签: java linux javafx gtk javafx-3d

我正在尝试关注此javafx 3d tutorial,但是我收到以下错误(我通过安装32位gtk2软件包和库清除了几个早期的错误),但是这个问题似乎没有失败那个。我在网上找不到同样的错误。

注意:我没有fxml文件(我不认为我需要一个,因为我在代码中设置了所有文件)

运行ubuntu 16.04.3 Elementary OS Loki

错误讯息:

Gtk-Message: Failed to load module "pantheon-filechooser-module"
Gtk-Message: Failed to load module "gail"
Gtk-Message: Failed to load module "atk-bridge"
Gtk-Message: Failed to load module "canberra-gtk-module"
Exception in thread "main" 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:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.NullPointerException
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:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
... 5 more

代码:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.shape.Box;
import javafx.stage.Stage;

public class GraphicsApplication extends Application {

public void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
    Box box = new Box(100,100,100);
    box.setTranslateX(150);
    box.setTranslateY(100);

    PointLight light = new PointLight();
    light.setTranslateX(300);
    light.setTranslateY(350);
    light.setTranslateZ(200);

    PerspectiveCamera camera = new PerspectiveCamera();
    camera.setTranslateX(100);
    camera.setTranslateY(-50);
    camera.setTranslateZ(300);

    Group root = new Group(box, light);

    Scene scene = new Scene(root, 400, 200, true);
    scene.setCamera(camera);

    primaryStage.setScene(scene);
    primaryStage.setTitle("Super test 5000");
    primaryStage.show();
}
}

1 个答案:

答案 0 :(得分:3)

main()方法必须为static