I've seen a number of questions about this issue but no conclusive answers. I am having trouble calling a Java class from my Worklight adapter implementation. I replaced my code with the code from the IBM Worklight Java Adapter tutorial and it fails in the exact same way. Furthermore I found a response on IBM's site saying the Java 1.7 compiler might cause this problem and to use Java 1.6 instead. I validated that my compiler in Eclipse is Java 1.6.
My Java classes all begin with com (e.g. com.worklight.customcode). I've tried both calling public static methods (using the proper syntax) as well as instantiating the object and calling the method. As mentioned above, I've also validated I'm using the Java 1.6 compiler.
Here are some code samples:
Adapter implementation file:
function addTwoIntegers(a,b){
return {
result: com.worklight.customcode.Calculator1.addTwoIntegers(a,b)
};
}
Java file (unedited IBM Worklight sample): package com.worklight.customcode;
import java.util.logging.Logger;
public class Calculator1 {
private final static Logger logger = Logger.getLogger(Calculator1.class.getName());
public static int addTwoIntegers(int first, int second){
logger.info("addTwoIntegers invoked");
return first + second;
}
public int subtractTwoIntegers(int first, int second){
logger.info("subtractTwoIntegers invoked");
return first - second;
}
}
Error in the console:
TypeError: Cannot call property addTwoIntegers in object [JavaPackage com.worklight.customcode.Calculator1]. It is not a function, it is "object". (%2FUsers%2Fhome%2Fdev%2Fapp%2Fappprj%2Fadapters%2Fadapter/adapter-impl.js#26) FWLSE0101E: Caused by: null
Some of the related questions are: