У меня были проблемы с интерфейсами Java. В основном у меня есть этот ICardApplMgr
, который должен быть унаследован ISCPCardApplMrg
. Мои интерфейсы как таковые:
public interface ISCPCardApplMrg extends ICardApplMgr { }
public interface ICardApplMgr {
public String getLossCount(String nric, boolean flag, String serialNumber);
}
Для класса реализации:
public class SCPCardApplMrgImpl extends BaseApplMgrImpl implements ISCPCardApplMrg {
public SCPCardApplMrgImpl() {
super();
}
public String getLossCount(String nric, boolean flag, String serialNumber) { //logic }
}
Затем я получил этот класс обслуживания, который будет вызывать функцию в классе MgrImpl выше:
@Service("cardApplication")
public class CardApplicationServiceImpl implements CardApplicationService {
protected ISCPCardApplMrg scpCardMgr;
public void setScpCardMgr(ISCPCardApplMrg mgr) {
this.scpCardMgr = mgr;
}
public ICardApplMgr getCardAppMgr(String itemCode) {
ICardApplMgr ret = null;
if (Constants.SCP_ITEM_CODE.equals(itemCode)) {
ret = scpCardMgr;
}
if (ret == null) {
log.warn("Null Manager found for itemCode " + itemCode);
}
return ret;
}
public String getLossCount(String nric, boolean flag, String itemCode, String serialNumber) {
return getCardAppMgr(itemCode).getLossCount(nric, flag, serialNumber);
}
}
Однако, когда я попытался вызвать getLossCount()
, внутри этой функции в getCardAppMgr()
я получил NullPointerException
. Сообщение об ошибке как таковое:
Exception in executing doSCPCardLoss java.lang.NullPointerException
at sc.appMgt.business.service.impl.CardApplicationServiceImpl.getLossCount(CardApplicationServiceImpl.java:385)
at sc.appMgt.presentation.controller.SCPCardCardLossController.doSCPCardLoss(SCPCardCardLossController.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at sc.idms.common.filter.SessionFilter.doFilter(SessionFilter.java:368)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3701)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3667)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2443)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2291)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2269)
at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1703)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1663)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:355)
Есть идеи, как решить эту проблему? Спасибо!