当我想从java类调用适配器时,我得到空指针异常
在下面的行中是错误,没有获得DataAccessService
DataAccessService dataAces = WorklightBundles.getInstance().getDataAccessService();
答案 0 :(得分:0)
您没有分享太多信息,但您的代码应该类似于以下内容,并应用了适当的修改(适配器名称,过程名称,参数等):
import com.ibm.json.java.JSONObject;
import com.worklight.server.bundle.api.WorklightBundles;
import com.worklight.server.integration.api.DataAccessService;
import com.worklight.server.integration.api.InvocationResult;
import com.worklight.server.integration.api.ProcedureQName;
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");
}