В то время как l oop вызывает сбой моего приложения JavaFX - PullRequest
0 голосов
/ 19 февраля 2020

Я пытаюсь проверить мои ArrayLists (которые хранятся в классе GrocerieList) и добавить их в мои ветви TreeView. Я могу отображать одиночные, не перебирая время l oop. Так как они динамические c, мне нужен какой-то l oop. В настоящее время ArrayList foodAmount ("4") и foodList ("pizza") оба содержат по одному элементу каждый.

Вот мой код с l oop (я исключил другие ветви для удобства чтения):

public class Main extends Application {

    Stage window;
    TextField nameInput, quantityInput;
    TreeView<String> tree;

    GrocerieList shoppingList = new GrocerieList();
    Storage storage = new Storage();
    static Scanner scan = new Scanner(System.in);
    static String item;
    static String quant;
    static String exit = "exit";
    static int menuchoice;
    static int catchoice;
    static int marketchoice;

    public static void main(String[] args) throws FileNotFoundException {
        loadFile();
        launch(args);

    }

    public void start (Stage primaryStage) throws Exception{

        window = primaryStage;
        window.setTitle("GrocerieList");

        // tree view
        TreeItem<String> root, food, drink, hygiene, other;

        root = new TreeItem<>();
        root.setExpanded(true);

        // food
        food = makeBranch("Food",root);
        while(GrocerieList.foodList.listIterator().hasNext()) {
            makeBranch("[" + GrocerieList.foodAmount.listIterator().next() + "] " + GrocerieList.foodList.listIterator().next(), food);
        }

        // tree
    tree = new TreeView<>(root);
    tree.setShowRoot(false);
    tree.getStyleClass().add("myTree");

    // bottom input fields
    nameInput = new TextField();
    nameInput.setPromptText("Productname");
    nameInput.setMinWidth(100);

    quantityInput = new TextField();
    quantityInput.setPromptText("Quantity");
    quantityInput.setMinWidth(100);

    // buttons
    Button addbutton = new Button("Add");

    // Layout
    // HBOX
    HBox hBox = new HBox();
    hBox.setPadding(new Insets(10));
    hBox.setSpacing(30);
    hBox.getChildren().addAll(nameInput, quantityInput, addbutton);

    // BorderPane
    BorderPane borderPane = new BorderPane();
    borderPane.setCenter(tree);
    borderPane.setBottom(hBox);
    borderPane.setPadding(new Insets(20));

    Scene scene = new Scene(borderPane, 520, 620);
    scene.getStylesheets().add("Viper.css");
    window.setScene(scene);
    window.show();

Это класс, который содержит мои ArrayLists:

public class GrocerieList {

    static ArrayList<String> foodList = new ArrayList<>();
    static ArrayList<String> hygieneList = new ArrayList<>();
    static ArrayList<String> drinkList = new ArrayList<>();
    static ArrayList<String> otherList = new ArrayList<>();

    static ArrayList<String> foodAmount = new ArrayList<>();
    static ArrayList<String> hygieneAmount = new ArrayList<>();
    static ArrayList<String> drinkAmount = new ArrayList<>();
    static ArrayList<String> otherAmount = new ArrayList<>();
}

Любая помощь будет принята:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...