4

I seem to be having problems figuring out why the heck I keep getting these java.net.ConnectExceptions. I'm running Windows 7 with a clean install of Java 7u6 x64. I've turned off my firewall (in case that was the issue). I've followed the solutions posted here:

java.net.SocketException: Invalid argument: connect

But nothing is getting rid of these issues. I've even used the Microsoft FixIt application to reset my IP stack. I've also added the "-Djava.net.preferIPv4Stack=true" to the environment variable JAVA_TOOL_OPTIONS variable. Nothing has worked.

This is a JavaFX "Hello World" program from the Netbeans IDE. (On my Mac I have no problems.)

Any help would be GREATLY appreciated! I'm no longer sure where to look to solve this. The end result is that every JavaFX program takes a long time to run. It appears they are all waiting for the timeouts of the socket connections before moving forward with the application. This is not occurring with Java programs, only JavaFX.

Here is the code:

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

And here is the Exception list:

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)
Community
  • 1
  • 1
slow-runner
  • 145
  • 9

2 Answers2

4

It's FX vs system proxy issue, FX is trying to check system proxy and failing if it's misconfigured. The reason for that is next enhancement: http://javafx-jira.kenai.com/browse/RT-21705

Add next to JVM arguments in project properties: "-Djavafx.autoproxy.disable=true" or fix system proxy to resolve that.

Sergey Grinev
  • 32,585
  • 8
  • 125
  • 136
  • Thanks!!! That did it! Now I need to fix the system proxy (as you stated)! Instead of doing it in the project properties, I changed my system variable JAVA_TOOLS_OPTIONS to this: JAVA_TOOLS_OPTIONS=-Djavafx.autoproxy.disable=true All is well – slow-runner Aug 22 '12 at 13:04
-1

Shouldn't you be running different app than you supposed, cause that sample code has nothing to do with network connection. Also check the JavaFX Runtime Platform of the Netbeans and hence of your app. You can find it in "Java Platforms" under "Tools" menu.

Uluk Biy
  • 46,036
  • 11
  • 134
  • 150