當(dāng)我按下按鈕 loadMap 時,我應(yīng)該能夠選擇一個文件(圖像)并且它應(yīng)該被上傳到我擁有的 borderpane 的中心,但是一旦我選擇一個文件,我就會不斷收到錯誤和 NullPointerException。我試過將它作為內(nèi)部類作為處理程序,但它是同樣的問題。這是以下代碼:public class Karta extends Application { final int LIST_CELL_HEIGHT = 26; TextField textfield; RadioButton b1; RadioButton b2; Label label = new Label("Categories"); ListView<String> lView; Button hideC; Button New; Button search; Button hide; Button remove; Button coordinate; FileChooser fileChooser; File file; ImageView imageView; ObservableList<String> items = FXCollections.observableArrayList("Bus", "Train", "Underground"); ListView<String> list = new ListView<>(items); MenuBar fileMenu; Stage primaryStage; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; BorderPane root = new BorderPane(); New = new Button("New"); b1 = new RadioButton("Named"); b2 = new RadioButton("Described"); ToggleGroup group = new ToggleGroup(); b2.setToggleGroup(group); b1.setToggleGroup(group); VBox vInTopH = new VBox(5); vInTopH.getChildren().addAll(b1, b2); textfield = new TextField("Search.."); search = new Button("Search"); hide = new Button("Hide"); remove = new Button("Remove"); coordinate = new Button("Coordinate"); HBox topHbox = new HBox(5); topHbox.getChildren().addAll(New, vInTopH, textfield, search, hide, remove, coordinate); topHbox.setAlignment(Pos.CENTER); VBox topVbox = new VBox(10);結(jié)果應(yīng)該是所選文件在設(shè)置時填充邊框的中心。
1 回答

米脂
TA貢獻1836條經(jīng)驗 獲得超3個贊
檢查代碼的第 121 行,您正在嘗試訪問空變量的成員:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at Karta.lambda$0(Karta.java:121)
...
很可能是imageView
被設(shè)置為null
而不是預(yù)期的有效對象引用。這將是拋出異常的行引用:
imageView.setImage(image);
可能需要更多細(xì)節(jié)才能進行更深入的分析。
添加回答
舉報
0/150
提交
取消