我正在使用grails版本:2.3.7來構建我的應用程序。當我運行我的應用程序,我得到的錯誤與空指針異常創建豆(完整的日誌如下)錯誤context.GrailsContextLoader - 初始化應用程序時出錯
| Running Grails application
2015-03-02 14:52:45,663 [localhost-startStop-1] INFO context.ContextLoader - Root WebApplicationContext: initializatio
n started
2015-03-02 14:52:45,769 [localhost-startStop-1] INFO support.XmlWebApplicationContext - Refreshing Root WebApplication
Context: startup date [Mon Mar 02 14:52:45 CET 2015]; root of context hierarchy
2015-03-02 14:52:45,830 [localhost-startStop-1] INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from S
ervletContext resource [/WEB-INF/applicationContext.xml]
2015-03-02 14:52:46,098 [localhost-startStop-1] INFO support.DefaultListableBeanFactory - Pre-instantiating singletons
in org.s[email protected]168484c: defining beans [grailsApplication,plug
inManager,grailsConfigurator,grailsResourceLoader,characterEncodingFilter,conversionService]; root of factory hierarchy
2015-03-02 14:52:50,516 [localhost-startStop-1] INFO context.ContextLoader - Root WebApplicationContext: initializatio
n completed in 4852 ms
2015-03-02 14:53:01,121 [localhost-startStop-1] INFO quartz.SchedulerFactoryBean - Shutting down Quartz Scheduler
Error |
2015-03-02 14:53:01,610 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application:
Error creating bean with name 'com.orga.odbc.DashboardController': Instantiation of bean failed; nested exception is or
g.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.orga.odbc.DashboardController]
: Constructor threw exception; nested exception is java.lang.NullPointerException
Message: Error creating bean with name 'com.orga.odbc.DashboardController': Instantiation of bean failed; nested excepti
on is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.orga.odbc.DashboardCon
troller]: Constructor threw exception; nested exception is java.lang.NullPointerException
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanInstantiationException: Could not instantiate bean class [com.orga.odbc.DashboardController]: Constructor
threw exception; nested exception is java.lang.NullPointerException
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by NullPointerException: null
->> 16 | <init> in com.orga.odbc.DashboardController
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . in java.lang.Thread
| Error Forked Grails VM exited with error
什麼couldbe的原因是什麼?如何調試它? 我會在回覆後添加其他資源
這是我的DashboardController.groovy
。它擴展了LoginController
,我在登錄時保存了用戶名會話。
package com.orga.odbc
import grails.plugin.mail.MailService;
// import org.compass.core.engine.SearchEngineQueryParseException
import java.awt.TexturePaintContext.Int;
import com.sun.org.apache.xerces.internal.util.Status;
class DashboardController extends LoginController {
//static String WILDCARD = "*"
//def searchableService
def usr = DbUser.findByLoginNameIlike(session.username) // Find DbUser reference to the current user
ApplicationUtilityService appUtilService = new ApplicationUtilityService()
MailService mailService
def notifierService
def index(Integer max) {
log.info("***DASHBOARD***")
int objCount = 0, dropObjCount = 0
int schCount = 0, dropSchCount = 0
int progressSch
int progressObj
params.max = Math.min(max ?: 25, 100)
params.sort = params.sort?:"objects"
params.order = params.order?:"desc"
params.offset = params.offset?:0
if(session.username.equals('admin')){ // If user is admin
log.info('redirecting to admin index')
render(view:"../index")
}
else if(usr){ // If user found
def dbUsrSchSrvInstList = DbUserSchemaServer.findAllByUser(usr, [sort:params.sort, order:params.order, max:params.max, offset: params.offset]) // Schema, server info for current user
def usrQuota
appUtilService.updateUserStatus(usr) // Update the status of the current user
if(usr.quota){
usrQuota = [
name: usr.quota.identifier, // Quota identifier
schAllowed: usr.quota.maxSchemaCount, // Max. number of schemas allowed
objAllowed: usr.quota.maxObjectCount // Max. number of objects allowed
]
// Count total number of objects used
HashMap<String, BigInteger> schObjCount = appUtilService.getSchObjCount(usr)
schCount = schObjCount.get("SCHEMAS") // Schema count for the current user status no drop
objCount = schObjCount.get("OBJECTS") // Object count for the current user status no drop
dropSchCount = schObjCount.get("DROP_SCHEMAS") // Schemas with drop status
dropObjCount = schObjCount.get("DROP_OBJECTS") // Objects with drop status
if(usrQuota.schAllowed != 0 && usrQuota.objAllowed != 0){ // protect from divided by zero
progressSch = (schCount/usrQuota.schAllowed) * 100 // Schema usage current user
progressObj = (objCount/usrQuota.objAllowed) * 100 // Object usage current user
}
}
else{ // If user has no quota (May not happen for almost every user)
usrQuota = [
name: 'No quota assigned', // Quota identifier
schAllowed: 0, // Max. number of schemas allowed
objAllowed: 0 // Max. number of objects allowed
]
schCount = 0
progressSch = 0
progressObj = 0
}
log.info('progress schema: '+ progressSch)
log.info('progress objects: '+ progressObj)
log.info('Total number of objects: '+ objCount+dropObjCount)
// Search procedure
// def searchParamsList, searchParams, results_duplicates, results = []
// If no query string, display all users list
//if(!params.queryString){
results = dbUsrSchSrvInstList
//}
// Else display results
/* else{
try {
String searchTerm = WILDCARD+params.queryString+WILDCARD // take search term
searchParamsList = searchableService.search(dbUsrSchSrvInstList, searchTerm) // search matching term
searchParams = searchParamsList.results // Collect results
// Find results match with the current user
results_duplicates = searchParams.findAll{
it.id in dbUsrSchSrvInstList*.id
}
// Find by server name. Match results and append to results list
results_duplicates = results_duplicates.plus(dbUsrSchSrvInstList.findAll {
it.server.id in searchParams.id
})
// remove duplicates in results
results_duplicates.id.unique().each {
results.add(DbUserSchemaServer.get(it))
}
} catch (SearchEngineQueryParseException ex) {
ex.printStackTrace()
}
} */
//return parameters
[ dbUserInstance: usr,
dbUsrSchSrvInstList: results,
schCount: schCount,
totalSchCount: schCount + dropSchCount,
objCount:objCount,
totalObjCount: objCount + dropObjCount,
usrQuota:usrQuota,
progressSch: progressSch,
progressObj: progressObj
] // return list of schemas related to the current user
}
}
}
原因在stacktrace中解釋。您可以修復DashboardController的第16行中的空指針異常(它在構造函數中)。爲了進行調試,您可以在IDE中設置斷點。 – cfrick 2015-03-02 14:30:43