when i was working on a small project of mine, i stumpled upon a weird error the Java compiler gives me, when i want to compile the code. The compilar says that i have an unhandled Interruptedexception. This is because i use Thread.sleep(). Here in my code you can clearly see that i handle the exception, but still the compiler insists that i dont. Instead of doing it this way I also tried doing it by using a try/catch block, but this also did not help. The weird thing also is the compiler does not give me an error if i do buttonpress(); instead of generate.setOnAction(e -> buttonpress()); (generate is just a button). The line java complains about is the last line in my first code block. Here is my code:
@FXML
@Override
public void start(Stage primaryStage) throws InterruptedException, IOException {
window = primaryStage;
window.setTitle("RNG");
Parent root = FXMLLoader.load(getClass().getResource("FXML.fxml"));
lowerbound = (TextField) root.lookup("#lowerboundinput");
upperbound = (TextField) root.lookup("#upperboundinput");
output = (Text) root.lookup("#randomnumberoutput");
Button generate = (Button) root.lookup("#generatebutton");
generate.setOnAction(e -> buttonpress());
Here is the buttonpress method:
public static void buttonpress()throws InterruptedException{
if(!lowerbound.getText().equals("")|| !upperbound.getText().equals("")) {
RandomNumberGenerator.JavaFXLauncher(lowerbound.getText(), upperbound.getText());
}else{
setOutput("EMPTY");
}
}
and here is the JavaFXLauncher method:
public static void JavaFXLauncher(String firstbound, String secondbound) throws InterruptedException{
int random;
try {
if(inputvalidator(firstbound, secondbound)) {
random = Integer.parseInt(firstbound) + (int) (Math.random() * ((Integer.parseInt(secondbound) - Integer.parseInt(firstbound)) + 1));
Main.setOutput(Integer.toString(random));
TimeUnit.MILLISECONDS.sleep(50);
//some other code
} catch(NumberFormatException e){
Main.setLowerbound("Pick smaller number");
Main.setUpperbound("Integer overflow");
} catch (InterruptedException f){
}
}