繁体   English   中英

java bean空指针异常

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM