简体   繁体   中英

How to prevent NullPointerException in a Java Class in Domino agent

My assumption is that, checking if the first document is null should be enough to prevent a nullexception error but that is not the case.

I cannot seem to find where the exception is coming from and how to prevent it.

Below is the error log:

Agent Manager: Agent printing: Create Report error:  null
Agent Manager: Agent  error: java.lang.NullPointerException
Agent Manager: Agent  error:  at JavaAgent.createReport(Unknown Source)
Agent Manager: Agent  error:  at JavaAgent.NotesMain(Unknown Source)
Agent Manager: Agent  error:  at lotus.domino.AgentBase.runNotes(Unknown Source)
Agent Manager: Agent  error:  at lotus.domino.NotesThread.run(Unknown Source)

Below are the functions being called

        private void createReport() {
        Integer qCount = 0;
        Document qDoc = null;
        ViewNavigator vNav = null;

        try {
            qView = currentDatabase.getView("RecsByRNo");
            qDoc = qView.getFirstDocument();
            vNav = qView.createViewNav();

            while (qDoc != null) {

                String qNo = qDoc.getItemValueString("RNo");
                String qType = qDoc.getItemValueString("EType");
                String qStatus = qDoc.getItemValueString("Status");
                String qBy = qDoc.getItemValueString("RBy");

                Document tmpReqDoc = qView.getNextDocument(qDoc);
                qDoc.recycle();
                qDoc = tmpReqDoc;
            }

        } catch (Exception e) {
            logErrors("Create Report error: ", e);

        } finally {
            try {
                qView.recycle();
                qDoc.recycle();
                vNav.recycle();
            } catch (Exception e) {
            }
        }

        agentLogger.LogAction("<<< Count: " + qCount + " >>>");
    }

    private void logErrors(String t, Exception e) {
        agentLogger.LogError(t + " " + e.getMessage());
        agentLogger.LogError(t + " " + e.getStackTrace().toString());
        System.out.println(t + " " + e.getMessage());
        e.printStackTrace();
    }

Any recommendation will be appreciated.

Turn on the option „Compile Java code with debugging information“ in the agent properties to get the line number of the error in the Java stacktrace. This should give you some hints. currentDatabase might be null or the view does not exist.

Turn on "compile Java code with debugging information" so you know where the error is

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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