线程 "WindowsNativeRunloopThread"java.lang.NoSuchMethodError : <init> 中的 JavaFX 异常

标签 java windows javafx javafx-8

我刚刚在这里写了这段代码:

package SpellcheckerClient;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = FXMLLoader.load(getClass().getResource("/controller/gui.fxml"));
            Scene scene = new Scene(root);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.setTitle("Spellchecker Client");           
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

这就是相应的 Controller 。

package controller;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import spellchecker.remote.SpellcheckerRemoteAdapter;

public class Controller {
    @FXML
    TextField input;
    @FXML
    Button send;
    @FXML
    TextArea area;  
    @FXML
    Button connect;

    private SpellcheckerRemoteAdapter adapter;

    @FXML
    private void send() throws RemoteException{
        String toCheck = input.getText();
        this.area.appendText(toCheck + "\n");
        this.area.appendText(checkRoutine(toCheck, this.adapter) + "\n\n");
        this.input.clear();
    }

    public void initiateConnection() {
        try {           
            Registry registry = LocateRegistry.getRegistry(1088);
            this.adapter = (SpellcheckerRemoteAdapter) registry.lookup(SpellcheckerRemoteAdapter.NAME);
            this.area.appendText("Verbindung erfolgreich aufgebaut!\n");
            connect.setDisable(true);
        } catch (Exception e) {
            if(this.adapter == null) {
                this.area.appendText("Server nicht gefunden!\n");
            }
        }
    }

    private static String checkRoutine(String input, SpellcheckerRemoteAdapter adapter) throws RemoteException {
        if (input == null || input.isEmpty()) {
            return "Bitte etwas eingeben!";
        }
        String[] words = input.split(" ");
        boolean control = true;
        String output = "";
        for(String word : words) {
            if(!adapter.check(word)) {
                control = false;
                output += word + ":\t" + adapter.getProposal(word) + "\n";
            }
        }
        if(control) {
            return "Alles Okay!\n";
        }
        return output;
    }


}

如果我在我编写代码的笔记本电脑上运行这段代码,它在 Eclipse 中运行得非常好,并且作为可运行的 Jar 运行。但是,如果我尝试在另一台计算机上运行 JAR,我会收到以下错误消息:

Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
        at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source) 

Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
        at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source) 

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
        at javafx.graphics/com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit(Unknown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

我的笔记本电脑和我的计算机上安装的 JDK/JRE 版本相同。 我真的不明白错误消息告诉我什么。

最佳答案

您好,我在 Eclipse 环境(Windows 10 操作系统)上遇到了同样的问题, 添加 VM 选项 -Djava.library.path="C:\WINDOWS\Sun\Java\bin"解决了我的问题

这意味着 javafx-graphics-[version]-win.jar 调用一些 native dll。你必须找到那些 dll 的存储位置。 感谢 jvisualvm 并显示了应用程序正确运行情况下的 VM 选项,我找到了路径。

希望能解决您的问题。

关于线程 "WindowsNativeRunloopThread"java.lang.NoSuchMethodError : <init> 中的 JavaFX 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50590250/

相关文章:

windows - 如何查找文件是否在 Windows 的文件系统缓存中?

windows - linuXploit_crew 攻击了我的网络服务器

java - 将 Spring 与 JavaFX Service 类集成会导致 Service 失败

JavaFx - 更新 GUI

JavaFX 缩放打印弄乱了我的打印机

java - RequestParam 的自定义验证不适用于 Spring MVC

java - JAXB:仅将必需的属性复制到对象

java - 如何从网页打印数据?不是页面的html代码。

java - 在基于ARM的lubuntu linux上运行LibGDX游戏?

windows - startxwin - cygwin 上的 startx