Reputation: 336
after searching online, BindException occurs when a port is already in use. But i've only used this port number once. Here is my code.
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);}
}
According the stack trace, the error occurs on line5 when I try to create an instance of ServerUI on line10. Not sure how to debug this. Help is appreciated.
Upvotes: 1
Views: 4332
Reputation: 64700
Depending on your framework version and development environment, this usually means there is an old version of this app running. Check that all other instances of the app have been stopped/killed.
Upvotes: 0
Reputation: 259
To free a port on a Windows computer, run command prompt as administrator and execute the following commands:
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.
Upvotes: 1