title: creating objects and adding them to group
body: <p><strong>Introduction</strong></p>
  
  <p>I want to create some Rectangles but I always see a nullPointerExeption or I cannot give as many arguments as I want.
  I cannot make Rectangle (width,height,x,y,paint,paint(stroke)) so I decided to use RectangleBuilder object.</p>
  
  <p>Here is how I did it.</p>
  
  <pre><code>    @FXML
  public void group() {
     // RB.applyTo(r);
      for (double i = 0; i &lt; 5; i++) {
  
          pane.getChildren().add(new Group(g));
          r.setStroke(Color.BLACK);
          r.setY(i * 25 + 80);
          r.setX(100.0);
  
          r.setStroke(Color.BLACK);
          r.getParent();
          RB.y(r.getY());
          RB.x(r.getX());
          RB.height(r.getHeight());
          RB.width(r.getWidth());
          RB.stroke(r.getStroke());
          RB.fill(r.getFill());
          g.getChildren().add(RB.build());
      }
  
  }
  </code></pre>
  
  <p>And here are the objects:</p>
  
  <p><code>@FXML
      Pane pane = new Pane();
          @FXML
      Rectangle r = new Rectangle();
      Group g = new Group();
      protected RectangleBuilder RB = null;</code></p>
  
  <p>I do not really know if I should use RB.getX or RB.applyto(r).</p>
  
  <p><strong>Problem</strong></p>
  
  <p>is in : RB.x(r.getX()): etc.</p>
  
  <p>or in RB.applyto(r); when I delete the comment marks on this line.</p>
  
  <p>Problem is in RB when I try to get info about r Rectangle.
  I can easily turn on program but when I click on button with action "group" it gave me Error :</p>
  
  <ul>
  <li>"NullPointerException"</li>
  <li>"IllegalArgumentExpression"</li>
  </ul>
  
  <p><strong>Error Data</strong></p>
  
  <pre><code>java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1456)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
      at javafx.event.Event.fireEvent(Event.java:171)
      at javafx.scene.Node.fireEvent(Node.java:6867)
      at javafx.scene.control.Button.fire(Button.java:179)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
      at javafx.event.Event.fireEvent(Event.java:171)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3369)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3209)
      at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3164)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1582)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2267)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:530)
      at com.sun.glass.ui.View.notifyMouse(View.java:924)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
      at java.lang.Thread.run(Thread.java:744)
  Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1453)
      ... 44 more
  Caused by: java.lang.NullPointerException
      at group.FXMLDocumentController.group(FXMLDocumentController.java:45)
      ... 54 more
  </code></pre>
  
  <p>I do not know if it is so important.</p>
  
  <p>By the way line 45 is :</p>
  
  <pre><code> RB.y(r.getY());
  </code></pre>