gpt4 book ai didi

JavaFX2.0 webview不渲染页面?

转载 作者:行者123 更新时间:2023-11-30 09:35:32 25 4
gpt4 key购买 nike

我在JavaFX2.0中写了如下代码

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

/**
*
* @author roger
*/
public class WebViewDemo extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {

StackPane root = new StackPane();
WebView x = new WebView();
WebEngine ex = x.getEngine();
ex.load("http://www.google.com");
root.getChildren().add(x);
Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
}

我收到以下错误并且无法弄清楚哪里出了问题?

Jul 03, 2012 11:18:42 PM com.sun.webpane.webkit.network.URLLoader doRun
WARNING: Unexpected error
java.lang.IllegalArgumentException: Illegal cookie name
at java.net.HttpCookie.<init>(HttpCookie.java:158)
at java.net.HttpCookie.parseInternal(HttpCookie.java:964)
at java.net.HttpCookie.parse(HttpCookie.java:215)
at java.net.HttpCookie.access$100(HttpCookie.java:58)
at java.net.HttpCookie$12.parse(HttpCookie.java:1096)
at sun.net.www.protocol.http.HttpURLConnection.filterHeaderField(HttpURLConnection.java:2605)
at sun.net.www.protocol.http.HttpURLConnection.getFilteredHeaderFields(HttpURLConnection.java:2642)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2686)
at com.sun.webpane.webkit.network.URLLoader.extractHeaders(URLLoader.java:776)
at com.sun.webpane.webkit.network.URLLoader.willSendRequest(URLLoader.java:574)
at com.sun.webpane.webkit.network.URLLoader.doRun(URLLoader.java:155)
at com.sun.webpane.webkit.network.URLLoader.access$000(URLLoader.java:42)
at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:104)
at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:101)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.webpane.webkit.network.URLLoader.run(URLLoader.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

请让我知道哪些地方需要修改,哪些地方出了问题?

最佳答案

我发现了一些 google-fu this导致此错误的论坛帖子 RT-15676 .该帖子建议添加以下行:

java.net.CookieHandler.setDefault(null);

在应用程序启动之后但在启动 WebView 之前。所以我把它放在将根 StackPane 添加到场景之前。它现在似乎起作用了。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewDemo extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {

StackPane root = new StackPane();
WebView x = new WebView();
WebEngine ex = x.getEngine();
ex.load("http://www.google.com");

root.getChildren().add(x);
java.net.CookieHandler.setDefault(null);
Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}

}

关于JavaFX2.0 webview不渲染页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11316444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com