title: Can't add a Shape to GridPane from array
body: <p>As an assignment, I'm making a Slot Machine program in JavaFX.</p>
  
  <p>If I do this:</p>
  
  <pre><code>GridPane grid = new GridPane();
  grid.add(new Rectangle(20, 20), 0, 0);
  </code></pre>
  
  <p>it works. But if I do this:</p>
  
  <pre><code>GridPane grid = new GridPane();
  Shape[] shapes = new Shape[6];
  Rectangle square = new Rectangle(20, 20);
  shapes[0] = square;
  grid.add(shapes[0], 0, 0);
  </code></pre>
  
  <p>it will not. it returns the following compile-time error</p>
  
  <pre><code>    Executing D:\Libraries\Documents\NetBeansProjects\SlotMachine\dist\run624299409\SlotMachine.jar using platform C:\Program Files\Java\jdk1.8.0_60\jre/bin/java
  Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: 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$156(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=50.0, vgap=50.0, alignment=CENTER
      at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
      at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
      at javafx.scene.layout.GridPane.add(GridPane.java:965)
      at slotmachine.SlotMachine.start(SlotMachine.java:71)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
      ... 1 more
  Exception running application slotmachine.SlotMachine
  Java Result: 1
  </code></pre>
  
  <p>I've also tried to change the array type and declared it as <code>Rectangle[]</code>, but still it won't compile.</p>
  
  <p>I don't understand why. In <code>shapes[0]</code> I do have a <code>Rectangle</code>, why won't it allow me to add it to the grid?</p>
  
  <p>EDIT: I'm using an array because once a Spin button is clicked, a random shape will be displayed (a random index from 0 to 5)</p>