调用NotesCalendar.getNewInvitations方法时出现异常。

NotesException: NotesCalendar error: The database handle is NULL
    at lotus.domino.local.NotesCalendar.NgetNewInvitations(Native Method)
    at lotus.domino.local.NotesCalendar.getNewInvitations(Unknown Source)
    at JavaAgent.main(Unknown Source)


我正在尝试在Domino服务器本地运行此代码。

import lotus.domino.*;

public class JavaAgent extends NotesThread {

public static void main(String []args){
    try
        {
            NotesThread.sinitThread(); // start thread
            Session session = NotesFactory.createSession();
            System.out.println("session="+session);
            // (Your code goes here)
            DbDirectory dbdir = session.getDbDirectory("");
            System.out.println("dbdir="+dbdir);
           Database db1= session.getDatabase("server", "Conf");


            NotesCalendar cal = session.getCalendar(db1);


            java.util.Calendar jdt = java.util.Calendar.getInstance();
            jdt.set(2015, 1, 1, 1, 1, 1);
            DateTime dt1 = session.createDateTime(jdt);
            DateTime dt2 = session.createDateTime("Yesterday 02");
          //  java.util.Vector invites = cal.getNewInvitations(dt1, dt2);
          //  System.out.println("invites "+invites.size());
            java.util.Vector invites= cal.getEntries(dt1, dt2);
            for (int j = 0; j < 3; j++) {
            // Create document to post results
            Document doc = db1.createDocument();
            doc.appendItemValue("Form", "main");
            doc.appendItemValue("subject", "New invitations");
            RichTextItem body = doc.createRichTextItem("body");
            if (invites.size() == 0) body.appendText("No invitations");
            else {
              for (int i = 0; i < invites.size(); i++) {
                  NotesCalendarNotice cale = (NotesCalendarNotice)invites.elementAt(i);
                  body.appendText(cale.read());
               cale.recycle();
                  body.addNewLine();
              }
            }
            doc.save(true, true);
            java.util.concurrent.TimeUnit.MINUTES.sleep(30);
            invites = cal.getNewInvitations(dt1, cal.getUntilTime());
        } }
            catch(Exception e)
        {
            e.printStackTrace();
        }
            finally
        {
            NotesThread.stermThread(); // must terminate every thread
        }
     }
}

最佳答案

简单的答案是getNewInvitations()在资源预留数据库的上下文中没有意义。该方法旨在读取邮件文件中未处理的邀请。

但是,在注释中,您说您的代码也不适用于邮件文件。获得更简单的工作然后在此基础上构建可能会有所帮助。我只是尝试了以下代码:

        database = session.getDatabase(null, "mail/user.nsf");
        NotesCalendar calendar = session.getCalendar(database);

        // Start date is 01-Jan-2015
        java.util.Calendar start = java.util.Calendar.getInstance();
        start.set(2015, 0, 1);
        dtStart = session.createDateTime(start);

        // End date is now
        java.util.Calendar end = java.util.Calendar.getInstance();
        dtEnd = session.createDateTime(end);

        // Get entries on the calendar between start and end
        Vector<?> entries = calendar.getEntries(dtStart, dtEnd);
        System.out.println("Number of entries is " + entries.size());

        // Get invitations from start date (from the Inbox)
        Vector<?> invites = calendar.getNewInvitations(dtStart, calendar.getUntilTime());
        System.out.println("Number of invites is " + invites.size());


一切都按预期进行。也许您可以尝试上面的代码,看看getNewInvitations()是否仍然引发异常。

09-30 23:35