8

Most dignified developers,

I'm having trouble invoking a method on my own java class from a lotus script agent.

My Java class simplified looks like this

import lotus.domino.*;

public class MyClass{
   /* .. omitted constructor and other methods .. */

   public void myMethod(Document doc){
      /* ... do things with the document object ...*/
   }

}

Now this class is included with the proper use statement, and I can iterate over the classmethods on the class object in lotus script to get the signature of the arguments needed.

But when I try to invoke the method I get a LS2J: Parameter mismatch calling Method myMethod

I've tried both with dot notation on the JavaObject (No I'm not using a Mac ;)) and ADT

Dim doc as NotesDocument
Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject

...

Set jSession = New JavaSession()
Set jClass = jSession.Getclass("MyClass")

Set jObject = jClass.Createobject()
Call jObject.myMethod(doc)

and respectively

Dim jMethod as JavaMethod
...

Set jMethod = jClass.Getmethod("myMethod", "(Llotus/domino/Document;)V")
tmp = jMethod.Invoke(jObject,doc)

Also I've added error handling (OnError ..) to print out the results of any JavaError (+ stacktrace) but they end up empty so no further clues there.

I'm using Designer version 9.0

Any ideas/pointers/gotchas? It's driving me bald.

1
  • voteup for the opening of the question > dignified :) love it Nov 12, 2015 at 9:56

2 Answers 2

9

You are using the correct approach to calling your Java method but you can not pass Notes backend objects as parameters.

You can parse a string with the document universal id, for instance, and then in your Java method look up the document using the universal id.

Alternatively, migrate your Lotusscript logic to Java :-)

1
  • 1
    Ah, they should put that in bold, red and font size 28 in the help. ;) And yes, this ls2j ordeal was mainly an idea I had of writing a "wrapper" around my java util class for those LS only internal folks. Luckily I never promised anyone anything ;) May 28, 2014 at 17:54
1

Maybe you don't need CreateObject..

This is how I do it:

Dim jSession As New JavaSession()
Dim jClass As JavaClass()
Set jClass = jSession.GetClass("MyClass")

If jClass.myMethod(doc) Then

Full example added

Java class:
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class GetFileFromUrl {

    public static boolean getFileFromUrl(String imageUrl, String filePath) {
        try {
            URL url = new URL(imageUrl);
            InputStream is = url.openStream();
            OutputStream os = new FileOutputStream(filePath);
            byte[] b = new byte[2048];
            int length;
            while ((length = is.read(b)) != -1) {
                os.write(b, 0, length);
            }
            is.close();
            os.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

LotusScript:

UseLSX "*javacon"  
Use "GetFileFromUrl"

Private Function GetFileFromUrl(url As String, outputPath As String) As Boolean
    Dim jSession As New JavaSession
    Dim jClass As JavaClass
    Set jClass = jSession.GetClass("GetFileFromUrl")
    If jClass.getFileFromUrl(url, outputPath) Then
        GetFileFromUrl = True
    End If
End Function
3
  • Thanks for the swift reply Casper, but are you sure about that? That renders me a Instance member MYMETHOD does not exist error. May 28, 2014 at 13:56
  • I have added a full working example, maybe it makes more sense. May 29, 2014 at 15:24
  • Appreciate it Casper. Im guessing my error then was calling a non-static method ;) May 30, 2014 at 6:39

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.