How to add an array ItemMenu MenuBatton in JavaFX?

Read from a file, translate the string into an array of words. Give the name of each itemMenu added array itemMenu into a 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();
 leghtArray int = items.size() - 1;
 while (leghtArray > -1){
 MenuItem menuItem = new MenuItem();
menuItem.setText(items.get(leghtArray));
leghtArray--;
items1.add(menuItem);
}
this cooperation is.getItems().addAll(items1);
 } catch (IOException e) {
e.printStackTrace();
 }</menuitem></string>

Crashes this error...
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(of the 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.The 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 line!
items1.add(menuItem);
July 9th 19 at 13:02
1 answer
July 9th 19 at 13:04
You items1 = null, fix this:
List<menuitem> items1 = new ArrayList<>();</menuitem>
Now writes the same error, only in the line of this cooperation is.getItems().addAll(items1); - Millie_Bechtel commented on July 9th 19 at 13:07

Find more questions by tags JavaJavaFXUser interface