invoke function from executeAction within the class

2
Hi, I am calling other function from executeAction function. I defined my function // BEGIN EXTRA CODE and // END EXTRA CODE . But i am getting null pointer exception. How to invoke this function from executeAction function. CODE: // This file was generated by Mendix Modeler. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package myfirstmodule.actions; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import myfirstmodule.proxies.Binder; import myfirstmodule.proxies.Doc; import com.genpact.veeva.api.VeevaAPI; import com.genpact.veeva.apiImpl.VeevaImpl; import com.genpact.veeva.httpUtil.Document; import com.genpact.veeva.httpUtil.Section; import com.mendix.core.CoreException; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.systemwideinterfaces.core.IMendixObject; import com.mendix.webui.CustomJavaAction; public class GetBinders extends CustomJavaAction<IMendixObject> { private String authToken; private Long biderId; public GetBinders(IContext context, String authToken, Long biderId) { super(context); this.authToken = authToken; this.biderId = biderId; } @Override public IMendixObject executeAction() throws Exception { // BEGIN USER CODE // throw new // com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented"); List<IMendixObject> binders = new LinkedList<IMendixObject>(); /* * Doc doc=new Doc(getContext()); * * doc.setdoc_Id("12345"); doc.setdoc_name("Doc1"); * * Binder binder= new Binder(getContext()); * binder.setbinder_Id("B123456"); binder.setbinder_Name("Binder1"); * * doc.setDoc_Binder(binder); doc.commit(); * * * Doc doc1=new Doc(getContext()); doc1.setdoc_Id("12346"); * doc1.setdoc_name("Doc2"); * * Binder binder2= new Binder(getContext()); * binder2.setbinder_Id("B123457"); binder2.setbinder_Name("Binder2"); * * doc1.setDoc_Binder(binder2); doc1.commit(); * binders.add(binder.getMendixObject()); * binders.add(binder2.getMendixObject()); */ VeevaAPI api = new VeevaImpl(); com.genpact.veeva.httpUtil.Binder binder = api.retriveBinder(authToken, (long) biderId); Binder binder_proxy = new Binder(getContext()); binder_proxy.setbinder_Id(binder.getId().toString()); binder_proxy.setbinder_Name(binder.getName__v()); List<Section> sections = binder.getSections(); List<Document> documents = null; myfirstmodule.proxies.Section sec_proxy = null; Doc doc_proxy = null; for (Section section : sections) { sec_proxy = new myfirstmodule.proxies.Section(getContext()); sec_proxy.setsec_Name(section.getName__v()); sec_proxy.setsecId(section.getId()); sec_proxy.setSection_Binder(binder_proxy); sec_proxy.commit(); documents = section.getDocuments(); List<Section> sub_sections = section.getSections(); recursiveSub(sub_sections, sec_proxy); for (Document document : documents) { doc_proxy = new Doc(getContext()); doc_proxy.setdoc_Id(document.getDocument_id__v().toString()); doc_proxy.setdoc_name(document.getName__v()); doc_proxy.setDoc_Section(sec_proxy); doc_proxy.commit(); } } /* * VeevaAPI api=new VeevaImpl(); List<com.genpact.veeva.httpUtil.Binder> * bindersList=api.retriveBinder(authToken); * * Binder binder=null; Doc doc=null; List<Document> documents=null; * * for (com.genpact.veeva.httpUtil.Binder b : bindersList) { * * documents=b.getDocuments(); * * binder=new Binder(getContext()); * binder.setbinder_Id(b.getId().toString()); * binder.setbinder_Name(b.getName__v()); * * for (Document document : documents) { doc=new Doc(getContext()); * doc.setdoc_Id(document.getDocument_id__v().toString()); * doc.setdoc_name(document.getName__v()); doc.setDoc_Binder(binder); * doc.commit(); binders.add(binder.getMendixObject()); } } */ return binder_proxy.getMendixObject(); // END USER CODE } /** * Returns a string representation of this action */ @Override public String toString() { return "GetBinders"; } // BEGIN EXTRA CODE public void recursiveSub(List<Section> sub_sections, myfirstmodule.proxies.Section sec_proxy) throws CoreException { for (Section section : sub_sections) { myfirstmodule.proxies.Section subSection_proxy = sec_proxy .getSection_SubSection(); subSection_proxy.setsec_Name(section.getName__v()); subSection_proxy.setsecId(section.getId()); subSection_proxy.setSection_SubSection(sec_proxy); subSection_proxy.commit(); List<Document> documents = section.getDocuments(); Doc doc_proxy = null; for (Document document : documents) { doc_proxy = new Doc(getContext()); doc_proxy.setdoc_Id(document.getDocument_id__v().toString()); doc_proxy.setdoc_name(document.getName__v()); doc_proxy.setDoc_Section(subSection_proxy); doc_proxy.commit(); } List<Section> sections = section.getSections(); if (section != null && sections.size() > 0) { recursiveSub(sections, subSection_proxy); } } } // END EXTRA CODE } ERROR: com.mendix.modules.microflowengine.MicroflowException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at MyFirstModule.GET_Binders (JavaAction : 'GetBinders') Advanced stacktrace: at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:143) Caused by: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at com.mendix.core.component.InternalCore.execute(InternalCore.java:385) Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at com.mendix.core.actionmanagement.ActionManager.executeSync(ActionManager.java:178) Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:36) Caused by: java.lang.NullPointerException: null at com.genpact.veeva.apiImpl.VeevaImpl.getRecursiveSections(VeevaImpl.java:152) at com.genpact.veeva.apiImpl.VeevaImpl.retriveBinder(VeevaImpl.java:105) at myfirstmodule.actions.GetBinders.executeAction(GetBinders.java:71) at myfirstmodule.actions.GetBinders.executeAction(GetBinders.java:1) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:49) at com.mendix.core.actionmanagement.CoreAction.doCall(CoreAction.java:260) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:248) at com.mendix.core.actionmanagement.ActionManager$1.execute(ActionManager.java:168) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.core.actionmanagement.ActionManager.executeSync(ActionManager.java:174) at com.mendix.core.component.InternalCore.execute(InternalCore.java:377) at com.mendix.modules.microflowengine.actions.actioncall.JavaAction.execute(JavaAction.scala:52) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:192) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:149) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:49) at com.mendix.core.actionmanagement.CoreAction.doCall(CoreAction.java:260) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:248) at com.mendix.core.actionmanagement.ActionManager$1.execute(ActionManager.java:168) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.core.actionmanagement.ActionManager.executeSync(ActionManager.java:174) at com.mendix.core.component.InternalCore.execute(InternalCore.java:377) at com.mendix.webui.actions.client.ExecuteAction.execute(ExecuteAction.java:135) at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply$mcV$sp(ClientRequestHandler.scala:282) at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply(ClientRequestHandler.scala:277) at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply(ClientRequestHandler.scala:277) at com.mendix.core.session.Worker$$anonfun$receive$3$$anonfun$2$$anon$1.execute(ActionDispatching.scala:144) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.core.session.Worker$$anonfun$receive$3$$anonfun$2.apply(ActionDispatching.scala:146) at scala.util.Try$.apply(Try.scala:192) at com.mendix.core.session.Worker$$anonfun$receive$3.applyOrElse(ActionDispatching.scala:140) at akka.actor.Actor$class.aroundReceive(Actor.scala:465) at com.mendix.core.session.Worker.aroundReceive(ActionDispatching.scala:136) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516) at akka.actor.ActorCell.invoke(ActorCell.scala:487) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) at akka.dispatch.Mailbox.run(Mailbox.scala:220) at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
asked
2 answers
2

You should debug with Eclipse to find your null reference. Here is the how-to guide for doing so:

https://world.mendix.com/display/howto50/Debugging+Java+Actions

answered
0

Include a check

if (sub_sections != null) {
   for (Section section : sub_sections) {
answered