我似乎遇到問題,爲什麼我不斷收到這些java.net.ConnectExceptions。我使用乾淨的Java 7u6 x64安裝來運行Windows 7。我關閉了防火牆(如果是這個問題)。我已經按照張貼在這裏的解決方案:JavaFX Hello World在開始時拋出java.net.ConnectException
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)
謝謝!那樣做了!現在我需要修復系統代理(如您所述)!而不是在項目屬性中,我將我的系統變量JAVA_TOOLS_OPTIONS更改爲: JAVA_TOOLS_OPTIONS = -Djavafx.autoproxy.disable = true 一切都很好 –