Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

java - JavaFX WebView thows NoSuchMethod Exception

I'm trying to insert a simple WebView inside a VBox in a JavaFX application, the web view starts displaying but doesn't fully load and it starts throwing a NoSuchMethod Exception in loop coming from the javafx.web module; if I don't pass the mouse over it, stops throwing the exception. Seems like has some problems with the update of the view. Any fix or alternatives? (My goal is to display a zoomable map). Thanks for any help.

Here is the code where the webview is created:

public class RenterMapView extends VBox {

private final RoomRenterResultBean roomRenterResultBean;
private final SearchingView searchingView;
private final boolean comingFromSearch;

//UI
private final WebView webView = new WebView();
private final WebEngine webEngine = webView.getEngine();
private final Button backBtn = UIUtils.createStyledButton("Back", new BackAction());

public RenterMapView(RoomRenterResultBean roomRenterResultBean, SearchingView searchingView, boolean comingFromSearch) {
    this.roomRenterResultBean = roomRenterResultBean;
    this.searchingView = searchingView;
    this.comingFromSearch = comingFromSearch;
    this.buildMapVBox(roomRenterResultBean);
}

private void buildMapVBox(RoomRenterResultBean roomRenterResultBean) {
    Label nameLabel = new Label(roomRenterResultBean.getName());
    nameLabel.setStyle(Style.HEADER_TEXT);
    nameLabel.setPadding(new Insets(25, 0, 25, 25));
    this.getChildren().add(nameLabel);
    HBox padding = new HBox(this.backBtn);
    padding.setPadding(new Insets(0, 0, 0, 25));
    this.getChildren().add(padding);

    VBox webVBox = new VBox();
    webVBox.setPrefHeight(400);
    webVBox.setPrefWidth(600);
    webVBox.getChildren().add(webView);
    webEngine.load("http://www.google.com");
    this.getChildren().add(webVBox);
}

Here is the exception:

java.lang.NoSuchMethodError com.sun.prism.paint.ImagePattern.<init>(Lcom/sun/prism/Image;FFFFLcom/sun/javafx/geom/transform/BaseTransform;ZZ)V
at javafx.web/com.sun.javafx.webkit.prism.WCGraphicsPrismContext$6.doPaint(WCGraphicsPrismContext.java:795)
at javafx.web/com.sun.javafx.webkit.prism.WCGraphicsPrismContext$Composite.paint(WCGraphicsPrismContext.java:1519)
at javafx.web/com.sun.javafx.webkit.prism.WCGraphicsPrismContext$Composite.paint(WCGraphicsPrismContext.java:1504)
at javafx.web/com.sun.javafx.webkit.prism.WCGraphicsPrismContext.drawPattern(WCGraphicsPrismContext.java:801)
at javafx.web/com.sun.webkit.graphics.GraphicsDecoder.drawPattern(GraphicsDecoder.java:410)
at javafx.web/com.sun.webkit.graphics.GraphicsDecoder.decode(GraphicsDecoder.java:205)
at javafx.web/com.sun.webkit.graphics.WCRenderQueue.decode(WCRenderQueue.java:92)
at javafx.web/com.sun.webkit.WebPage.paint2GC(WebPage.java:740)
at javafx.web/com.sun.webkit.WebPage.paint(WebPage.java:707)
at javafx.web/com.sun.javafx.sg.prism.web.NGWebView.renderContent(NGWebView.java:95)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics/com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:479)
at javafx.graphics/com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:321)
at javafx.graphics/com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at javafx.graphics/com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.base/java.lang.Thread.run(Thread.java:834)

Example:

public class Main extends Application {
public void start(Stage primaryStage) {
    WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    webEngine.load("http://www.google.com");
    Scene scene= new Scene(webView,800,600);
    primaryStage.setScene(scene);
    primaryStage.show();
}

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

}

EDIT

For those who are facing the same issue, make sure you are using the same version of modules javafx-graphics, javafx-web and javafx-media. In my case this was the problem.

question from:https://stackoverflow.com/questions/65904855/javafx-webview-thows-nosuchmethod-exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...