We help IT Professionals succeed at work.

I want to write a java agent in domino designer but it gets the error--"Could not find the main class:lotus.domino.local.java4.Program will exit"

nicedone
nicedone used Ask the Experts™
on
Hi,

I am trying to make a Java Agent in Domino Designer but since I am a newbie  ,I somehow could not get a simple agent to work.

Can you guide me how to proceed?

Here is the code ; I wrote it under java icon in domino designer 8.5.3

---------------------------------------------------------------------------------------------------------------
package lotus.domino.local;

import lotus.domino.*;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;

public class java4 {

      /**
       * @param args
      */
      
      public static void main(String[] args) {
            // TODO Auto-generated method stub
            try
            {
               NotesThread.sinitThread();
               Session s = NotesFactory.createSession();
               Database db = s.getDatabase("","mail/xxxxx.nsf");
               Document doc = db.createDocument();
               doc.replaceItemValue("Form", "Memo");
               doc.replaceItemValue("Subject", "Reminder");
               doc.replaceItemValue("Body","A document awaits your approval in " +
               db.getTitle() + ".");
               doc.send("RecipientCommon Name");
               System.out.println("memo sent.");
            }
            catch(Exception e)
            {
               e.printStackTrace();
            }
            finally
            {
               NotesThread.stermThread();
            }
      }

}
hata.JPG
javaagent.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sjef BosmanGroupware Consultant

Commented:
Go to Code/Agents, click right on it, click New Agent... then set a name and select the Java type, then click  Ok.
In Src, (default package), you see JavaAgent.java; double-click to open it

Author

Commented:
Thanks, when i put my code in it and hit run it asks me if as an applet or Application, if it is Application

i get "Selection does not contain main type" error.

if I select applet

i get "Selection does not contain an applet" error.

How can I fix this? I still could not get my code working?
Sjef BosmanGroupware Consultant

Commented:
When you create a Java agent, the code has to extend AgentBase, the way you found it when you opened the JavaAgent.java code for the first time. Your code goes where the comment is: // (Your code goes here)

Something like this (mind, I just pasted your code, no idea if it's correct!):
import lotus.domino.*;

public class JavaAgent extends AgentBase {

	public void NotesMain() {

		try {
			Session session = getSession();
			AgentContext agentContext = session.getAgentContext();

			try {
				Database db = s.getDatabase("", "mail/xxxxx.nsf");
				Document doc = db.createDocument();
				doc.replaceItemValue("Form", "Memo");
				doc.replaceItemValue("Subject", "Reminder");
				doc.replaceItemValue("Body",
						"A document awaits your approval in " + db.getTitle()
								+ ".");
				doc.send("RecipientCommon Name");
				System.out.println("memo sent.");
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window

Author

Commented:
Thanks for your help but the problem is when running the agent.

When i hit the run button in the designer it prompts me to choose applet or application
-------------------------------------------------------------------------------------------------------------------------
when i choose Application;

i get "Selection does not contain main type" error.

When I select applet

i get "Selection does not contain an applet" error.

How can I run the agent?
Groupware Consultant
Commented:
Then don't hit the Run button in the Designer... Go to the Notes client, open the database and select the agent from the Actions menu.

Did you select, in the Agent properties, for the agent's target: None ?

Author

Commented:
Thank u it worked