,當端口已被使用時發生BindException。但我只用過一次這個端口號。這是我的代碼。java.net.BindException:地址已在使用中(綁定失敗),但在聯機搜索後端口僅使用一次
public class ServerUI extends Application {
private ServerSocket serverSocket = null;
public ServerUI() throws IOException {
this.serverSocket = new ServerSocket(1111);
}
@Override
public void start(Stage primaryStage) throws Exception {
ServerUI server = new ServerUI();
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = (Parent)loader.load();
Controller controller = (Controller)loader.getController();
primaryStage.setTitle("Server");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {launch(args);}
}
根據堆棧跟蹤,當我嘗試在第10行上創建ServerUI的實例時,line5發生錯誤。不知道如何調試。幫助表示讚賞。
Windows還是Linux? – BCartolo