gpt4 book ai didi

JavaFX Hello World 在启动时抛出 java.net.ConnectException

转载 作者:行者123 更新时间:2023-12-01 02:32:46 25 4
gpt4 key购买 nike

我似乎在弄清楚为什么我不断收到这些 java.net.ConnectExceptions 时遇到问题。我正在使用全新安装的 Java 7u6 x64 运行 Windows 7。我已经关闭了我的防火墙(以防那是问题所在)。我已经按照此处发布的解决方案进行操作:

java.net.SocketException: Invalid argument: connect

但没有什么能摆脱这些问题。我什至使用 Microsoft FixIt 应用程序来重置我的 IP 堆栈。我还在环境变量 JAVA_TOOL_OPTIONS 变量中添加了“-Djava.net.preferIPv4Stack=true”。没有任何效果。

这是来自 Netbeans IDE 的 JavaFX“Hello World”程序。 (在我的 Mac 上我没有问题。)

任何帮助将不胜感激!我不再确定去哪里解决这个问题。最终结果是每个 JavaFX 程序都需要很长时间才能运行。在继续应用程序之前,它们似乎都在等待套接字连接的超时。这不会发生在 Java 程序中,只会发生在 JavaFX 中。

这是代码:

package anotherjavafxtest;

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.stage.Stage;

/**
*
* @author redacted
*/
public class AnotherJavaFXTest extends Application
{

@Override
public void start(Stage primaryStage)
{
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("Hello World!");
}
});

StackPane root = new StackPane();
root.getChildren().add(btn);

Scene scene = new Scene(root, 300, 250);

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

/**
* The main() method is ignored in correctly deployed JavaFX application. main() serves only as fallback in case the application can not be launched through deployment
* artifacts, e.g., in IDEs with limited FX support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}

这是异常(exception)列表:
java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2380)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1546)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.getJSFileFromURL(Unknown Source)
at com.sun.deploy.net.proxy.AbstractAutoProxyHandler.init(Unknown Source)
at com.sun.deploy.net.proxy.DynamicProxyManager.reset(Unknown Source)
at com.sun.deploy.net.proxy.DeployProxySelector.reset(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.tryToSetProxy(Main.java:572)
at com.javafx.main.Main.launchApp(Main.java:640)
at com.javafx.main.Main.main(Main.java:805)

最佳答案

这是 FX 与系统代理的问题,FX 正在尝试检查系统代理,如果配置错误,则会失败。原因是下一个增强功能:http://javafx-jira.kenai.com/browse/RT-21705

在项目属性中的 JVM 参数旁边添加:"-Djavafx.autoproxy.disable=true"或修复系统代理来解决这个问题。

关于JavaFX Hello World 在启动时抛出 java.net.ConnectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067368/

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