Die Verkleidung von Null-Pointer-Exception: Cannot invoke method firstMethod() on null Object : Grails 3.2.10

Schrieb ich eine einfache rest-api-Controller in Grails-version 3.2.10. Hier sind meine system-Konfigurationen. Erstellte Anwendung ist auch rest-api-Profil.

Grails-Version: 3.2.10
Groovy Version: 2.4.10
JVM, Version: 1.8.0_131

Beispielcode geschrieben ist, ist wie folgt:
Controller:

package mydevpath

import grails.rest.*
import grails.converters.*

class LoginController {
static responseFormats = ['json', 'xml']

def index() {
        def loginService
        def val = loginService.firstMethod()

        render 'hello World' + val
     }
   }

Service :`
Paket mydevpath

import grails.transaction.Transactional

 @Transactional
 class LoginService {
    static scope = "prototype"

     def firstMethod(){
        return 'From Service'
  }
}

Laufen und laufen und schlagen die URL , ich bin vor folgende Fehlermeldung.

NullPointerException occurred when processing request
: [POST] /login
Cannot invoke method firstMethod() on null object. Stacktrace follows:

java.lang.reflect.InvocationTargetException: null
        at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.
invoke(DefaultGrailsControllerClass.java:211)
        at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrai
lsControllerClass.java:188)

Kann mir jemand helfen mit dem Problem?

Grüße,
Pramod

  • loginService.firstMethod() verursacht Problem. wo ist loginService initialisiert?
Schreibe einen Kommentar