-2

I need to loop through an ArrayList of objects and add their ImageViews to my main Group which is root in the code below. This is what I came up so far but still not working. Any idea?

for (int i = 0; i < myList.size(); i++) {
    ImageView ii =myList.get(i).imageView;
    root.getChildren().remove(bGroup);
    Group bGroup = new Group();
    bGroup.getChildren().add(ii); //NullPointerException
    root.getChildren().add(bGroup);
}
I'mDoneOK
  • 39
  • 2
  • 9
  • Please explain what "not working" means. You get an exception? It doesn't compile? Something else? – James_D May 28 '18 at 17:20
  • Also, I just made the effort to fix your formatting. Is there some reason you felt it necessary to destroy it again? – James_D May 28 '18 at 17:22
  • i get NullPointerException – I'mDoneOK May 28 '18 at 17:24
  • @James_D i made a change – I'mDoneOK May 28 '18 at 17:25
  • 1. Include the complete stack trace in the question, and indicate the line in your code that is throwing it. 2. If you're going to make edits, please make an effort to format the question appropriately, so that it's easy to read. You can get information on how to format your code [here](https://meta.stackexchange.com/questions/22186/). – James_D May 28 '18 at 17:58

1 Answers1

0

myList.get(i) instead of myList.get(1)?

Rene Knop
  • 1,788
  • 3
  • 15
  • 27