0
votes

Below is the java sample code from worklight to invoke adapter.

public static void testAdapterCall(){
      try{
      DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
      String paramArray = "[5, 3,]";
      ProcedureQName procedureQname = new ProcedureQName("CalculatorAdapter", "addTwoIntegers");
      InvocationResult result = service.invokeProcedure(procedureQname, paramArray);
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }

    }

I'm getting a Null Pointer exception, when it goes to line

DataAccessService service = WorklightBundles.getInstance().getDataAccessService();

Log is as below:

java.lang.NullPointerException
at com.worklight.customcode.Calculator1.testAdapterCall(Calculator1.java:38)
at com.worklight.customcode.Calculator1.main(Calculator1.java:53)

Versions: Java 1.7 Worklight 6.2 The Adapter is deployed, and the server is also running locally. I saw this question in other sites also, but it is not answered.

Any help is highly appreciated.

1

1 Answers

0
votes

See the documentation in the following PDF document, starting page #13.

public void callProcedure() {
    DataAccessService service = worklightBundles.getInstance().getDataAccessService();
    String paramArray = "['param1', 'param2', 'param3']";
    ProcedureQName procedureQName = new ProcedureQName("adapterName",
"procedureName");
    InvocationResult result = service.invokeProcedure(ProcedureQName,
paramArray);
    JSONObject jsonObject = result.toJSON();
    String value = (String)jsonObject.get("key");
}

Be sure to add any missing includes once you enter the code into a Java IDE, such as Eclipse.