当我按下按钮 loadMap 时,我应该能够选择一个文件(图像)并且它应该被上传到我拥有的 borderpane 的中心,但是一旦我选择一个文件,我就会不断收到错误和 NullPointerException。我试过将它作为内部类作为处理程序,但它是同样的问题。这是以下代码: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);结果应该是所选文件在设置时填充边框的中心。
1 回答
米脂
TA贡献1836条经验 获得超3个赞
检查代码的第 121 行,您正在尝试访问空变量的成员:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at Karta.lambda$0(Karta.java:121)
...
很可能是imageView
被设置为null
而不是预期的有效对象引用。这将是抛出异常的行引用:
imageView.setImage(image);
可能需要更多细节才能进行更深入的分析。
添加回答
举报
0/150
提交
取消