![](/img/trans.png)
[英]Null pointer exception while accessing bean in java for already referred bean Spring mvc
[英]java bean null pointer exception
這是我的第一篇文章,因此希望我能夠達到社區的高標准。
我正在嘗試學習Enterprise Java bean,並且陷入了困境,並要求調試拋出NullPointerException
的EAR文件。 這是引發異常的行:
private CrashMonitorTimer crash;
...
/*THE NEXT LINE THROWS THE NULL POINTER EXCEPTION*/
crash.createTimer(Long.parseLong(sCrashMonitorInterval),"CrashMoniterScheduler");
這是被調用的接口的代碼:
import javax.ejb.Local;
@Local
public interface CrashMonitorTimer
{
public abstract void createTimer(long l, String s);
public abstract void cancelTimer(String s);
}
這是Java bean的代碼:
@Stateless(name = "CrashMonitorBean", mappedName = "CrashMonitorBean")
@Local(CrashMonitorTimer.class)
public class CrashMonitorBean
implements CrashMonitorTimer
{
@Resource
SessionContext sessionCtx;
TimerService timerService;
Timer timer;
int iMsgCntBeforeCtxRenew;
int iCtxReusedCount;
Context _context;
CrashMonitorInfoUtil crashMonitorRMIContext[];
public CrashMonitorBean()
{
iMsgCntBeforeCtxRenew = 10;
iCtxReusedCount = 0;
_context = null;
crashMonitorRMIContext = null;
}
@Override
public void createTimer(long lInterval, String sName)
{
//CrashMonitorInfoUtil leaves context open for reuse
System.out.println((new StringBuilder("Creating ")).append(sName).append(" timer").toString());
timerService = sessionCtx.getTimerService();
timer = timerService.createTimer(lInterval, lInterval, sName);
String sPorts = SystemConfigurator.getConfigValue("RMIPorts");
String saPorts[] = sPorts.split(",");
String server = SystemConfigurator.getConfigValue("host");
crashMonitorRMIContext = new CrashMonitorInfoUtil[saPorts.length];
for(int i = 0; i < saPorts.length; i++)
{
crashMonitorRMIContext[i] = new CrashMonitorInfoUtil(server, saPorts[i]);
}
}
...
}
我已經對此進行了探討,但是對Java Bean或接口(或新注釋)的使用經驗為零,我什至不知道該嘗試些什么。 任何解釋或指示將不勝感激。
crash
變量為null
。
如果sCrashMonitorInterval
為null,則將引發NumberFormatException
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.