以前那是我的代碼:FileNotFoundException異常在Java/JavaFX的搜索解決方案
import java.io.FileNotFoundException;
public class Bundesliga extends Application {
public static void main(String[] args) throws FileNotFoundException {
PlayerManager league = new PlayerManager();
league.uruchom();
}
}
當然還有另一類PlayerManager,但我認爲是不需要的。一切工作得很好,沒有錯誤。然後我試着用Javafx修改它。還有就是修改一個:
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class Bundesliga extends Application {
Stage window;
Scene scene1;
public static void main(String[] args) throws FileNotFoundException {
launch(args);
}
@Override
public void start(Stage primaryStage) throws FileNotFoundException {
PlayerManager league = new PlayerManager();
window = primaryStage;
Button button1 = new Button("Uruchom program");
button1.setOnAction(e -> league.uruchom());
StackPane layout = new StackPane();
layout.getChildren().add(button1);
scene1 = new Scene(layout, 600, 300);
window.setScene(scene1);
window.setTitle("Title here");
window.show();
}
}
我想通過點擊按鈕來運行我的代碼,但是當我試圖編譯它,錯誤occours:「Bundesliga.java:24:錯誤:未報告的異常FileNotFoundException;必須被捕獲或聲明爲拋出button1.setOnAction(e - > league.uruchom());我不知道該如何解決這個問題,因爲我的方法拋出FileNotFoundException,請幫幫我。
http://crunchify.com/better-understanding-on-checked-vs-unchecked-exceptions-how-to-handle-exception-better-way-in-java/和http://stackoverflow.com/問題/ 6115896/java-checked-vs-unchecked-exception-explanation – kosa