当我按下按钮 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);
结果应该是所选文件在设置时填充边框的中心。
米脂
相关分类