java - 基本 javafx 应用程序中由 NullPointer 引起的 InvocationTargetException

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

最佳答案

main() 方法必须是static

关于java - 基本 javafx 应用程序中由 NullPointer 引起的 InvocationTargetException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46240626/

相关文章:

tableview - javafx如何隐藏tableview的背景标题?

linux - 在 linux 中调用 sed

c - 将控制台分成不同的区域

java - 避免Java因证书错误而出现安全警告

java - 使用 JasperReport 库和 MongoDB 生成 PDF

linux - X11 依赖项,不使用 X11 编译 Dbus,仅启动 Shell C++ 应用程序 Raspbian Linux

JavaFX8 : add label on linechart and update them according to a zoom

java - 组合两个具有不同返回类型的 CompletableFuture 的结果

java - 带有自定义注释的 Spring AOP 不起作用

Java:如何让 File.listOfFiles 在 Linux 上非递归工作?