Calling a Java Script Library from Lotus Script Agent

Hi,

I am hoping someone can help me with a problem I am stumped on.

I have a Lotus Script Agent from which I call a Java Script Library. When executing the Java code there is a null pointer exception and the code bombs out.

I can put the Java Script Library into it’s own agent and can run it without any problems.

It seems to be failing when called from the agent on:

Session session = getSession();

This is the call to the Java Script Library from the Lotus Script agent:

Dim mySession As JavaSession

Dim myClass As JavaClass

Dim myObject As JavaObject

Dim myMethod As JavaMethod

Dim success As Boolean



Set mySession = New JavaSession()

Set myClass = mySession.GetClass("HWURLCommand")

Set myMethod = myClass.GetMethod("NotesMain","()V")

Set myObject = myClass.CreateObject() 



success = 999

success = myMethod.Invoke(myObject)



If success Then

'Do stuff

Else

'error occurred

End If

This is the Java Script Library:

import lotus.domino.*;

import java.io.*;

import java.net.*;

public class HWURLCommand extends AgentBase {

public void NotesMain(String x) {



	try {

		System.out.println("*** Started HWURLCommand ***");

		Session session = getSession();

		System.out.println("1");

		AgentContext agentContext = session.getAgentContext();

		System.out.println("2");

		Database db = agentContext.getCurrentDatabase();

	 	System.out.println("Title:\t\t" + db.getTitle());

		String dbFilename = db.getFileName();

		System.out.println("File name:\t" + db.getFileName());

//Do Stuff here

}

}

}

I get *** Started HWURLCommand ** to print out on the console and then get the following errors:

Agent Manager: Agent error: java.lang.NullPointerException

Agent Manager: Agent error: at HWURLCommand.NotesMain(HWURLCommand.java:12)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)

Agent Manager: Agent error: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)

Agent Manager: Agent error: at java.lang.reflect.Method.invoke(Method.java:391)

Agent Manager: Agent error: at lotus.domino.JavaConnectInvoker.invoke(Unknown Source)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)

Agent Manager: Agent error: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)

Agent Manager: Agent error: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)

Agent Manager: Agent error: at java.lang.reflect.Method.invoke(Method.java:391)

13/07/2009 05:57:58 PM Agent Manager: Agent error: at lotus.domino.JavaConnectLoader.invoke(Unknown Source)

This is exception message from the Lotus Script Agent:

Agent Manager: Agent printing: ***HW agent finished in Exception ***

Agent Manager: Agent message: Error in HW Invalid use of null on line 17

Any help would be appreciated.

Thanks.