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...
 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*"));
 leghtArray int = items.size() - 1;
 while (leghtArray > -1){
 MenuItem menuItem = new MenuItem();
this cooperation is.getItems().addAll(items1);
 } catch (IOException e) {

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(
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(
 at the
Caused by: java.lang.NullPointerException
 at sample.Main.start(
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(
 at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(
 at com.sun.javafx.application.PlatformImpl.lambda$null$173(
 at AccessController.doPrivileged(Native Method)
 at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(
 at Method)
 1 ... more

44 line!
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