简体   繁体   English

java bean空指针异常

[英]java bean null pointer exception

This is my first post, so hopefully I live up to the high standards of the community. 这是我的第一篇文章,因此希望我能够达到社区的高标准。

I'm trying to learn Enterprise Java beans and I've been thrown into the deep end and asked to debug an EAR file that's throwing a NullPointerException . 我正在尝试学习Enterprise Java bean,并且陷入了困境,并要求调试抛出NullPointerException的EAR文件。 This is the line that's throwing the Exception: 这是引发异常的行:

private CrashMonitorTimer crash;
...
/*THE NEXT LINE THROWS THE NULL POINTER EXCEPTION*/
crash.createTimer(Long.parseLong(sCrashMonitorInterval),"CrashMoniterScheduler");

This is the code for the interface being called: 这是被调用的接口的代码:

import javax.ejb.Local;

@Local
public interface CrashMonitorTimer
{
    public abstract void createTimer(long l, String s);

    public abstract void cancelTimer(String s);
}

And this is the code for the Java bean: 这是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]);
        }

    }
...
}

I've poked around at this, but having had zero experience with Java beans or interfaces (or the new annotations) I'm kind of at a loss on what I should even try. 我已经对此进行了探讨,但是对Java Bean或接口(或新注释)的使用经验为零,我什至不知道该尝试些什么。 Any explanation or direction would be greatly appreciated. 任何解释或指示将不胜感激。

crash variable is null . crash变量为null

If sCrashMonitorInterval were null, then it would have thrown NumberFormatException 如果sCrashMonitorInterval为null,则将引发NumberFormatException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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