2017-03-24 110 views
1

,當端口已被使用時發生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發生錯誤。不知道如何調試。幫助表示讚賞。

+0

Windows還是Linux? – BCartolo

回答

1

要釋放一個的Windows計算機上的端口,運行命令提示符管理員並執行以下命令:

netstat -o -n -a | findstr 0.0:1111 // finds the process using the port 
taskkill /F /PID 10880 // change 10880 with your PID number which you can see from the previous command. 
0

根據您的框架版本和開發環境,這通常意味着有一個運行此應用程序的舊版本。檢查應用程序的所有其他實例是否已被停止/殺死。

相關問題