Search code examples
javajavafxscenebuilder

JavaFX Webview NoSuchMethodError


I have a JavaFX application (I'm new to JavaFX) and in that application I have a WebView. There are no errors when I run the application until the webview loads the webpage. I have attempted to Google my way through the error the last three hours. I've read that the heap might not be big enough, so I allocated more memory to the VM heap. I've read that I have to specify the WebView module, which I also tried in VM arguments. I'm using IntelliJ and have no other errors in the project. The following error repeats about 10-15 times after the webpage loads in my application. No crash's, WebView appears to be functional, I just want to know why I have so many errors in my terminal when I run this application. If I need to provide anymore information please let me know, and my apologies beforehand. Using Maeven as my package manager.

ERROR

Exception in thread "JavaFX Application Thread" java.lang.NoSuchMethodError: 'com.sun.javafx.iio.ImageStorage com.sun.javafx.iio.ImageStorage.getInstance()'
at javafx.web@20-ea/com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:179)
at javafx.web@20-ea/com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:192)
at javafx.web@20-ea/com.sun.javafx.webkit.prism.WCImageDecoderImpl.addImageData(WCImageDecoderImpl.java:109)
at javafx.web@20-ea/com.sun.webkit.network.URLLoaderBase.twkDidReceiveData(Native Method)
at javafx.web@20-ea/com.sun.webkit.network.HTTP2Loader.notifyDidReceiveData(HTTP2Loader.java:566)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at javafx.web@20-ea/com.sun.webkit.network.HTTP2Loader.lambda$didReceiveData$17(HTTP2Loader.java:549)
at javafx.web@20-ea/com.sun.webkit.network.HTTP2Loader.lambda$callBackIfNotCanceled$10(HTTP2Loader.java:441)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)

LoginApplication Class

public class LoginApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
    FXMLLoader fxmlLoader = new FXMLLoader(LoginApplication.class.getResource("Login.fxml"));
    Scene scene = new Scene(fxmlLoader.load(), 1440, 900);
    stage.setTitle("Login");
    stage.setResizable(false);
    //Humble urself
    stage.setHeight(600);
    stage.setWidth(1000);
    stage.setScene(scene);
    stage.show();
    Repository repo = new Repository();
}

LoginController Class

public class LoginController implements Initializable {
@FXML
private Label welcomeText;
@FXML
private TextField txtUsername;
@FXML
private TextField txtPassword;
@FXML
private Button btnLogin;
@FXML
private WebView webViewNews;
@FXML
private Button btnCreateAccount;
@FXML
private Text txtPrompt;
private WebEngine webEngine;

@FXML
protected void onLoginClicked() throws SQLException {
    Repository repo = new Repository();
    if(txtUsername.getText() != "") {
        if(txtPassword.getText() != "") {
            //Stop user input while query is processed
            btnLogin.setDisable(true);
            btnCreateAccount.setDisable(true);
            txtPrompt.setText("Checking credentials... please wait.");

            //Check query and do stuff...
            if(repo.authenticateUser(txtUsername.getText(), txtPassword.getText())) {
                txtPrompt.setText("Login Success Welcome!");
                txtUsername.setVisible(false);
                txtPassword.setVisible(false);
                btnLogin.setVisible(false);
            } else {
                txtPrompt.setText("Login Failed! Invalid credentials.");
                btnLogin.setDisable(false);
                btnCreateAccount.setDisable(false);
                txtPassword.clear();
            }
        } else txtPrompt.setText("Password blank! Please enter a password.");
    } else txtPrompt.setText("Username blank! Please enter a username.");
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {

    webEngine = webViewNews.getEngine();
    webEngine.load("https://www.forums.blacksunstudios.us/index.php?pages/hideNews/");
}

Solution

  • Make sure you are using the same version of JavaFX for everything.

    Your stack trace indicates that you are using [email protected] and javafx.web@20-ea, so different versions for the graphics core and the webview component.

    Don't use early access software (ea) unless you have a specific need for it and, if you do, ensure you are using all of the compatible components required for it.

    But you don't need to use early access software here, instead, use [email protected], and the same version for all other JavaFX components.


    As an FYI, the ImageStorage.getInstance() method was added in this commit, for this issue, which is only applied to JavaFX versions 19+, which is why the 20ea software can try to use it but the 18.0.1 software does not supply it. If you wanted to support the feature from the issue:

    JDK-8277572 ImageStorage should correctly handle MIME types for images encoded in data URIs

    then use 19 as the version for all of your JavaFX dependencies.