Search code examples
javascalavaadin7

NullPointerException, While filling the IndexedContainer of vaadin in scala


I am trying to fill the IndexedContainer of Vaadin in Scala with the java.util.List[POJO].

Problem ? -> Throwing NullPointerException.

Where ? -> Place is Shown in Code snippet with Comment.

Note -> The different thing is, I am using iterator to fill the container. I have 7 objects, The things are going proper for 1 object but throwing exception during the insertion of 2nd object.

I am doing the same thing with other Hierarchical Containers and they are working proper.

Point : List is not having any null data item. output is also given in different snippet with the exception.

def getOtherAccessContainer(): IndexedContainer = {
    var container = new IndexedContainer
    container.addContainerProperty("User", classOf[Any], "-")
    container.addContainerProperty("user_id", classOf[Any], "-")
    container.addContainerProperty("User Group", classOf[Any], "-")
    container.addContainerProperty("user_familyid", classOf[Any], "-")
    container.addContainerProperty("Object Type", classOf[Any], "-")
    container.addContainerProperty("Object", classOf[Any], "-")
    container.addContainerProperty("object_id", classOf[Any], "-")
    container.addContainerProperty("Object Group", classOf[Any], "-")
    container.addContainerProperty("object_familyid", classOf[Any], "-")
    container.addContainerProperty("Permission", classOf[Any], "-")

    val access_list = accessor.getGrantedObjectList(accessibleuserlist);
    var iterator = access_list.iterator()

    var iterator2 = access_list.iterator()
    println()
    // Just to show that list of POJO is not having null value.
    while (iterator2.hasNext()) {
      val pojo_obj = iterator2.next()
      println(pojo_obj.username + "---" + pojo_obj.user_id + "---" + pojo_obj.user_familyname + "---" + pojo_obj.user_family_id + "---" + pojo_obj.object_type + "---" + pojo_obj.object_name +
        "---" + pojo_obj.object_id + "---" + pojo_obj.object_familyname + "---" + pojo_obj.object_family_id + "---" + pojo_obj.permission)
    }


    // This loop fills the data in container.
    while (iterator.hasNext()) {
      val pojo_obj = iterator.next()
      var child: Item = container.addItem()
      if (pojo_obj == null) {
        println("Trouble is here." + pojo_obj.username)
      }
      // Print some properties of POJO to be inserted before the Insertion is occured.     
      println("pojo_obj properties :-) " + pojo_obj.username + "---" + pojo_obj.object_name + "---" + pojo_obj.user_id + "---" + pojo_obj.user_familyname + "---" + pojo_obj.user_family_id)

      child.getItemProperty("User").asInstanceOf[Property[Any]].setValue(pojo_obj.username) // <- This line Throws the NullPointerException during 2nd Iteration.
      child.getItemProperty("user_id").asInstanceOf[Property[Any]].setValue(pojo_obj.user_id)// <- If I omitted the line above, It throws NullPointerException for this line and so on. 
      child.getItemProperty("User Group").asInstanceOf[Property[Any]].setValue(pojo_obj.user_familyname)
      child.getItemProperty("user_familyid").asInstanceOf[Property[Any]].setValue(pojo_obj.user_family_id)
      child.getItemProperty("Object Type").asInstanceOf[Property[Any]].setValue(pojo_obj.object_type)
      child.getItemProperty("Object").asInstanceOf[Property[Any]].setValue(pojo_obj.object_name)
      child.getItemProperty("object_id").asInstanceOf[Property[Any]].setValue(pojo_obj.object_id)
      child.getItemProperty("Object Group").asInstanceOf[Property[Any]].setValue(pojo_obj.object_familyname)
      child.getItemProperty("object_familyid").asInstanceOf[Property[Any]].setValue(pojo_obj.object_family_id)
      child.getItemProperty("Permission").asInstanceOf[Property[Any]].setValue(pojo_obj.permission.toString())

    }
    container
  }

Below is the Output:

parth---4cc19690-e819-11e5-a3a1-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
ravi---d1515310-e9ad-11e5-b18e-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
uttam---dca16200-e462-11e5-90ec-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
parth---4cc19690-e819-11e5-a3a1-c1cf090b354c---parth---4cc19690-e819-11e5-a3a1-c1cf090b354c---sa_table--- cluster_test---19713360-ed94-11e5-bf9e-c1cf090b354c---cluster_test---19713360-ed94-11e5-bf9e-c1cf090b354c---0
parth---4cc19690-e819-11e5-a3a1-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
uttam---dca16200-e462-11e5-90ec-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
ravi---d1515310-e9ad-11e5-b18e-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66---sa_table---App_Welcome---bce4bd70-ec34-11e5-bbd6-91bbc2299c26---system---9aa06252-e9c6-11e5-9ce9-5e5517507c66---1
pojo_obj properties :-) parth---App_Welcome---4cc19690-e819-11e5-a3a1-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66
pojo_obj properties :-) ravi---App_Welcome---d1515310-e9ad-11e5-b18e-c1cf090b354c---Analytics Team---ff81457a-e9cf-11e5-9ce9-5e5517507c66

16/04/04 11:50:42 ERROR DefaultErrorHandler: 
java.lang.NullPointerException
    at com.system.tableManager.TreeStructContainer.getOtherAccessContainer(TreeStructContainer.scala:245)
    at com.analytics.UI.views.ObjectLevelAccess$1.valueChange(ObjectLevelAccess.java:135)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
    at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1159)
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:570)
    at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:729)
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:468)
    at com.vaadin.ui.ComboBox.changeVariables(ComboBox.java:730)
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:603)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:422)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:79)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Solution

  • Some times Vaadin container addItem return null instead of new Item id.

    So, better option to use container.getItem(container.addItem) instead of container.addItem().

    Or add you own custom item Id like container.addItem(customId) for eatch item you want to add in container.