1

To help solve another problem I have, I'm testing the following code in the postGenerationProcess event of the POI Word widget:

var jce:writeXWPFDocument = new writeXWPFDocument();
var newString3 = jce.doSomething3(xwpfdocument);
print("newString3 = " + newString3);

doSomething3 is defined in a Java class contained in the .nsf.

public class writeXWPFDocument {

public String doSomething3(XWPFDocument xwpfdocument) {
    return "DO SOMETHING - xwpfdocument";
}}

When I run this code, I get the error:

Java method 'doSomething3(org.apache.poi.xwpf.usermodel.XWPFDocument)' 
on java class 'AZGPackage.writeXWPFDocument' not found

What could be causing this error? @Knut Hermann - this is a test which relates to the other problem you have been helping me with.

2 Answers2

1

Edit to make the correct answer easier to find:

I have used poi in a few applications. I've encountered similar problems twice: First, usually when I accidentally import a class with the same name from the wrong package (like lotus.local.domino.Database instead of lotus.domino.Database). The other time I encountered this (and the only time the package name was identical) was when I had poi in a plug-in that I had added to the build path and also had it installed by a poi extension library I had built. If you can't cast an object as itself, there is an issue with the ClassLoader, and I don't know what would cause that other than a class being listed twice.

Gary Forbis
  • 868
  • 1
  • 8
  • 19
  • no, that's not the problem. I can call other methods of this class which do not take xwpfdocument as an argument. –  Apr 11 '14 at 15:35
  • Have you set xwpfdocument above in your code like `var xwpfdocument:org.apache.poi.xwpf.usermodel.XWPFDocument = new org.apache.poi.xwpf.usermodel.XWPFDocument()`? If you prompt designer with `jce.` are you prompted with doSomething3(xwpfdocument) as a possible method? – Gary Forbis Apr 11 '14 at 18:26
  • When I declare the variable as you suggest, I get the error CLFAD0141E: Error processing XPage request. For more detailed information, please consult error-log-0.xml located in D:/Lotus/Domino/data/domino/workspace/logs –  Apr 14 '14 at 09:39
  • If I type jce, no method prompts are displayed. –  Apr 14 '14 at 09:40
  • Did you `importPackage(org.apache.poi)`? I'm very confused by the combination of issues here. It accepts an `Object` param and when you check `instanceof` on the object it is the correct class, but the method won't accept the correct class as an argument? The only way that makes any sense would be if you had two different XWPFDocuments on your buildpath, but as the package names match that doesn't seem to be the case. The only time I've seen anything like that was when I imported the same package in two different ways (such as imported into the app *and* in a plug-in). – Gary Forbis Apr 14 '14 at 11:02
  • I have added importPackage(org.apache.poi) but the result is the same. –  Apr 14 '14 at 11:16
  • java.lang.ClassCastException: org.apache.poi.xwpf.usermodel.XWPFDocument incompatible with org.apache.poi.xwpf.usermodel.XWPFDocument is the error I get when trying to cast Object to XWPFDocument –  Apr 14 '14 at 11:30
  • Okay, I'm pretty sure you have this package on your build path twice. That is the only way I know to get this error. How are you accessing poi? Have you imported it into the application? Did you put the .jar files in a folder under Notes? Do you have identical versions of poi installed in your designer and your local preview or server (whichever you are using)? – Gary Forbis Apr 14 '14 at 11:43
  • Please see http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class and http://www.coderanch.com/t/380416/java/java/Loading-class-class-loader-ClassCastException – Gary Forbis Apr 14 '14 at 11:46
  • The only poi .jar I now have on my build path is poi-3.10-FINAL-20140208.jar and the problem persists. Gary, have you managed to get this working? –  Apr 14 '14 at 12:50
  • I have used poi in a few applications. I've encounters similar problems twice: First, usually when I accidentally use a local class (like lotus.local.domino.Database and lotus.domino.Database). The other time I encountered this (and the only time the package name was identical) was when I had poi in a plug-in that I had added to the build path and also had it installed by a poi extension library I had built. If you can't cast an object as itself, there is an issue with the ClassLoader, and I don't know what would cause that other than a class being listed twice. – Gary Forbis Apr 14 '14 at 13:01
  • Hi, have at last gotten this working. I had imported the .jar files into the database (visible under JRE System Library) and had also installed the poi .jars in the jvm\lib\ext directory on the server. After deleting the .jars on the server, this now works! –  May 06 '14 at 12:42
0

SSJS seems to pass a different object type to the function. Try to change the class of the parameter to Object and for testing return the class name.

In a production code you could check with instanceof if the parameter has the right data type.

In General: consider using a facade pattern, so you keep your complex Java classes away from SSJS

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Using Object the method is found. However I would like to use the write method of the xwpfdocument and this does not work when xwpfdocument is passed as an Object. –  Apr 14 '14 at 09:11
  • org.apache.poi.xwpf.usermodel.XWPFDocument is returned when calling xwpfdocument.getClass() –  Apr 14 '14 at 09:20
  • While it wouldn't be a best practice, you could cast your `Object` back to XWPFDocument using `(XWPFDocument) object`. – Gary Forbis Apr 14 '14 at 11:05
  • I have tried casting the Object back to XWPFDocument but that also does not work :-( –  Apr 14 '14 at 11:23
  • Time for some refactoring :-) - In and out of SSJS is always a headache. Do you really need an XWPFDocument on the SSJS level? Create a Java class as Facade that interacts with the SSJS and only takes simple stuff like the OutputStream or a String as parameter. Makes it testable outside and removes a lot of headaches – stwissel Apr 15 '14 at 00:12