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

时间:2012-08-22 06:24:18

标签: javafx javafx-2

我似乎在弄清楚为什么我会继续获取这些java.net.ConnectExceptions。我正在运行Windows 7,干净安装Java 7u6 x64。我已经关闭了我的防火墙(如果是这个问题)。我按照这里发布的解决方案:

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);
    }
}

这是例外列表:

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)

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:-1)

你不应该运行不同的应用程序,因为该示例代码与网络连接无关。还要检查Netbeans的JavaFX运行时平台以及您的应用程序。您可以在“工具”菜单下的“Java平台”中找到它。