线程中的JavaFX异常&#34; WindowsNativeRunloopThread&#34; java.lang.NoSuchMethodError:<init>

时间:2018-05-29 17:55:40

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

这是相应的控制器。

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。 我并没有真正得到错误消息告诉我的内容。

2 个答案:

答案 0 :(得分:1)

您安装了哪个JDk?我遇到了同样的问题,我使用JDK 8而不是JDK9。这对我有所帮助。Sample Image of Exception

这是因为我创建的jar是通过其他系统在JDK 8上创建的。 当它在具有JDK9的另一个系统上执行时。因此它与版本不兼容。

在保留单个JDK 8并将其映射到系统环境后,当我尝试运行jar时,它对我有用。

祝你好运:)

答案 1 :(得分:0)

您好,我在Eclipse环境(Windows 10 OS)上遇到相同的问题, 在VM选项中添加-Djava.library.path =“ C:\ WINDOWS \ Sun \ Java \ bin”解决了我的问题

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

希望它能解决您的问题。