Error evaluating expression: Cannot invoke method getAt() on null object

Arthur Ronald picture Arthur Ronald · Oct 7, 2012 · Viewed 16.9k times · Source

I have a Question domain model designed as follows

class Question {

    List<Choice> choiceCollection;

    static hasMany = [choiceCollection:Choice]
    static mappping = {
        choiceCollection(joinTable:false)
    }

}

To fulfill my needs, /grails-app/views/question/create.gsp has been customized as you can see below

create.gsp

<g:each var="i" in="${(0..4)}">
    <div class="fieldcontain  required">
    <label for="description">
            Option ${i + 1}.
            <span class="required-indicator">*</span>
        </label>
        <g:textArea name="choiceCollection[${i}].description" cols="40" rows="5" maxlength="2000" value="${questionInstance?.choiceCollection[i]?.description}"/>
    </div>
</g:each>

When i try to access create view, i get the following error

Error evaluating expression [questionInstance?.choiceCollection[i]?.description]: Cannot invoke method getAt() on null object

Question: What should i do to run my application ?

Grails version: 2.1.1

Answer

miles zarathustra picture miles zarathustra · Jun 18, 2014

I observed this error when attempting to run grails (2.2.4) using Java 8. The cause was not immediately obvious. It's buried somewhere grails.util.BuildSettings.groovy

When I reverted to java 1.7, the message went away.