这是我的第一篇文章,希望我能够达到社区的高标准。
我正在尝试学习企业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或接口(或新注释)没有经验,我对我应该尝试的东西感到很茫然。任何解释或指示都将不胜感激。
答案 0 :(得分:0)
crash
变量为null
。
如果sCrashMonitorInterval
为空,则会抛出NumberFormatException