0

*UPDATED

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:

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
    }

My trace:

Message: null
    Line | Method
->>   45 | run       in matrices.MatrixFactorization
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     36 | <init>    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

MatrixFactorization class 35-45

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

Thanks in advance

4

2 に答える 2

0

The problem is at line 45 in the run method of the MatrixFactorization class as the 1st line of the stacktrace shows. The class is instantiating fine, but it's failing internally. Is there some missing configuration or setup before calling getAnswer()?

于 2013-01-07T16:01:51.770 に答える
0

Glad this worked for you. Here's the comment posted as an answer too.

Is the Java class in a package? I am assuming matrices because your code snippet doesn't show an import. I have experienced issues with accessing classes in the default package. Try putting it under a test package, if not already, and then import it in your controller.

于 2013-01-08T12:12:35.273 に答える