LinkedHashMap 插入内容时候的出现 null 对象错误

程序错误内容如下:

2013-06-12 16:42:43,805 [[email protected]] ERROR errors.GrailsExceptionResolver  - java.lang.NullPointerException: Cannot invoke method put() on null object
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NullPointerException: Cannot invoke method put() on null object
	at com.verani.common.web.servlets.SavedSearchFilter.doFilter(SavedSearchFilter.java:93)
	at com.verani.common.cms.servlets.PageFilter.doFilter(PageFilter.java:168)
	at com.verani.common.web.servlets.SavedSearchFilter.doFilter(SavedSearchFilter.java:57)
	at com.verani.common.cms.servlets.PageFilter.doFilter(PageFilter.java:168)
	at com.verani.common.web.servlets.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:38)
Caused by: java.lang.NullPointerException: Cannot invoke method put() on null object
	at com.verani.web.platform.controllers.ViperListingController$_closure21.doCall(com.verani.web.platform.controllers.ViperListingController:3081)
	at com.verani.web.platform.controllers.ViperListingController$_closure21.doCall(com.verani.web.platform.controllers.ViperListingController)
	... 5 more

这是因为程序定义: LinkedHashMap<String, String> basicDetails 如果这时候尝试向 LinkedHashMap put 数据,将会得到上面的错误。

可以将变量初始化为:LinkedHashMap<String, String> basicDetails = new LinkedHashMap<String, String>();就没有这个错误了。