title: I wanted to make a separate method for listeners in the root view but it throws NPE
body: <p>I have a <code>borderpane</code> as the root view and it was getting kind of big so I wanted to divide them into small chunks… with <code>View</code>s there is no problem, I can easily separate them into files and classes. </p>
  
  <p>The problem I am having is that when I want to make a separate method for <code>root</code> view's listeners, it is throwing NPE.</p>
  
  <p>This was my original code:</p>
  
  <pre><code>override val root = borderpane {
      addClass(rootStyle)
      paddingAll = 10.0
  
      // listeners
          setOnMouseEntered { scaleUp() }
  
          setOnMouseExited { scaleDown() }
      // end listeners
      center {...}
      }
  }
  </code></pre>
  
  <p>This is my current code that throws NPE:</p>
  
  <pre><code>override val root = borderpane {
      addClass(rootStyle)
      paddingAll = 10.0
  
      setListeners() // I added this
      center {...}
      }
  }
  
  private fun setListeners(){
       with(root) {
          setOnMouseEntered { scaleUp() }
  
          setOnMouseExited { scaleDown() }
      }
  }
  </code></pre>
  
  <p>I tried it without <code>with(root)</code> but IDE highlighted them as errors.
  I also tried to call the method in <code>onBeforeShow()</code>, it didn't throw any exceptions but listeners didn't work.</p>
  
  <p>What is a proper way to handle this? In Android I easily make <code>setListeners()</code> method and call it from <code>onCreate()</code>. What would be an optimal equivalent of this in TornadoFX?</p>
  
  <p><strong>Edited:</strong>
  I found a working code but still I am not sure if it is an optimal way... if you have better ways to handle this type of situations, feel free to add your answer.</p>