title: Grails groovyPageRenderer error: Cannot invoke method render() on null object
body: <p>I cannot get the Grails groovyPage Renderer to work without this error.  I have tried some various solutions but cannot seem to resolve it.  I have tried it on Grails 2.1.1 and 2.4.4 with both servlet 2.5 and 3.0.  Tried to follow the example on the blog below as well.</p>
  
  <p><a href="http://mrhaki.blogspot.com/2012/03/grails-goodness-render-gsp-views-and.html" rel="nofollow">http://mrhaki.blogspot.com/2012/03/grails-goodness-render-gsp-views-and.html</a></p>
  
  <p>Source:</p>
  
  <pre><code>class RenderTestController {
  
      static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
  
      def renderEx {
          def updateList= RenderService.updateRender()
      }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>package renderexample
  
  import grails.gsp.PageRenderer
  import java.util.List;
  import java.util.Map;
  
  class RenderService {
  
      public static List updateRender() {
  
          PageRenderer groovyPageRenderer
          def gspReturn = []
  
          gspReturn = [-1, 1, 2]
  
          def htmlBody = groovyPageRenderer.render(template:'/emails/_renderUpdate', model: [results: gspReturn])
  
          println htmlBody
  
          return gspReturn
      }
  }
  </code></pre>
  
  <p>Error 2015-08-10 15:39:45,801 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'renderexample.RenderTestController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [renderexample.RenderTestController]: Constructor threw exception; nested exception is java.lang.NullPointerException: Cannot invoke method render() on null object</p>
  
  <p>Message: Error creating bean with name 'renderexample.RenderTestController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [renderexample.RenderTestController]: Constructor threw exception; nested exception is java.lang.NullPointerException: Cannot invoke method render() on null object
      Line | Method
  ->>  262 | run       in java.util.concurrent.FutureTask</p>
  
  <p>Any help is appreciated. Thanks.</p>