title: Grails: using java class from controller
body: <p>*UPDATED</p>
  
  <p>I am new to grails and stack. I am trying to instantiate a java class in a controller. My .java file is in the /src folder. I have tested the class outside of grails and it works fine. However, when I try to instantiate it from a controller I get a null pointer exception. My relevant code:</p>
  
  <pre><code>package matrices
  
  import org.springframework.dao.DataIntegrityViolationException
  
  class MFController {
  
      static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
  
      def index() {
          MatrixFactorization m = new MatrixFactorization()
          def answer = m.getAnswer().toString()
          return answer
      }
  </code></pre>
  
  <p>My trace:</p>
  
  <pre><code>Message: null
      Line | Method
  -&gt;&gt;   45 | run       in matrices.MatrixFactorization
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  |     36 | &lt;init&gt;    in     ''
  |     10 | index . . in matrices.MFController$$ENtqy0Aa
  |    195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
  |     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
  |   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
  |    603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
  ^    722 | run       in java.lang.Thread
  </code></pre>
  
  <p>MatrixFactorization class 35-45</p>
  
  <pre><code>public MatrixFactorization() {
  
  double[] l1 = { 5, 3, 0, 1 };
  
  double[] l2 = { 4, 0, 0, 1 };
  
  double[] l3 = { 1, 1, 0, 5 };
  
  double[] l4 = { 1, 0, 0, 4 };
  
  double[] l5 = { 0, 1, 5, 4 }; //45
  </code></pre>
  
  <p>Thanks in advance</p>