Can't use DomainClass.get(id)

View: New views
6 Messages — Rating Filter:   Alert me  

Can't use DomainClass.get(id)

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I got nullpoint exception when use:
def act=Account.get(user.actId) // user.actId=3
Here is the error msg:
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException

        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)

        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)

        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1062)

        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:926)

        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893)

        at groovy.lang.Closure.call(Closure.java:279)

Thanks

Re: Can't use DomainClass.get(id)

by Benjamin Muschko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'd say that your user object is null. Try to log the value before you use it with Account.get() in your controller or service like this:

if(log.debugEnabled) {
   log.debug "User account ID: '${user.actId}'"
}

Re: Can't use DomainClass.get(id)

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am sure user.actId is not null.

Benjamin Muschko wrote:
I'd say that your user object is null. Try to log the value before you use it with Account.get() in your controller or service like this:

if(log.debugEnabled) {
   log.debug "User account ID: '${user.actId}'"
}

Re: Can't use DomainClass.get(id)

by Benjamin Muschko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does your Account class sit in the grails-app/domain directory?

Re: Can't use DomainClass.get(id)

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes,it's in domain directory, I have tried delete this class, and run the following script:

grails creaet-domain-class Account
grails generate-all Account


Benjamin Muschko wrote:
Does your Account class sit in the grails-app/domain directory?

Re: Can't use DomainClass.get(id)

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Found the reason,it's because of the relationship between my domains is wrong.



Yes,it's in domain directory, I have tried delete this class, and run the following script:

grails creaet-domain-class Account
grails generate-all Account


Benjamin Muschko wrote:
Does your Account class sit in the grails-app/domain directory?