Читаем из файла, переводим строку в массив слов. Даем название каждому itemMenu, добавляем массив itemMenu в menuButton...
@Override
public void start(Stage primaryStage) throws Exception{
List<String> items = null;
List<MenuItem> items1 = null;
try {
File file = new File("./subgroup.xml");
FileReader reader = new FileReader(file);
BufferedReader in = new BufferedReader(reader);
String string;
while ((string = in.readLine()) != null) {
int lenght = string.length();
string = string.substring(1, lenght-1);
items = Arrays.asList(string.split("\\s*,\\s*"));
}
in.close();
int leghtArray = items.size() - 1;
while (leghtArray > -1){
MenuItem menuItem = new MenuItem();
menuItem.setText(items.get(leghtArray));
leghtArray--;
items1.add(menuItem);
}
idGroup.getItems().addAll(items1);
} catch (IOException e) {
e.printStackTrace();
}
Вылетает такая ошибка...
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at sample.Main.start(Main.java:44)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Это 44 строка!
items1.add(menuItem);