showing null point exception when findAllBy - for session object

96 views Asked by At

I have already checked that session.parent_id and session.id_of_project is not null in the below code in gsp

        <g:if test="$session.parent_id">
        <g:set var="permission" value="${Project_permission.findAllById_of_projectAndParent_id(session.id_of_project, session.parent_id)}"/>

        <g:each var="emp" in="${permission}">

          <g:set var="employee2" value="${Employee.findById(emp.id_of_employee)}"/>
            <li class="parent_li">
              <span class="badge red" title="Collapse this branch">
                <i class="fa fa-minus-sign">
                </i> Child
            </span> 
              <a href="">Anyhing can go here!
              </a>
            </li>
          </g:each>
          </g:if>              

But it keep on showing:

Error 500: Internal Server Error java.lang.NullPointerException Message Cannot invoke method findAllById_of_projectAndParent_id() on null object

1

There are 1 answers

0
David Chavez On BEST ANSWER

Try adding this at the begining of your gsp:

<%@ page import="package.Project_permission" %>
<%@ page import="package.Employee" %>

Replace package with the actual package.

Anyway if you are going to findById, its better to do a Employee.get(id)