title: org.zkoss.zk.ui.UiException and java.lang.IndexOutOfBoundsException in java?
body: <p>I have an issue regarding UiException and IndexOutOfBoundsException. Here is my stack trace:</p>
  
  <p>Logcatlog:</p>
  
  <pre><code>Dec 10, 2013 11:03:49 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1359
  SEVERE: &gt;&gt;org.zkoss.zk.ui.UiException: Index: 1, Size: 0
  &gt;&gt;java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
  &gt;&gt;  at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
  &gt;&gt;  at java.util.ArrayList.add(Unknown Source)
  &gt;&gt;  at com.csdcsystems.amanda.web.viewmodel.ToolbarCustomizeViewModel.getModulesList(ToolbarCustomizeViewModel.java:187)
  &gt;&gt;  at com.csdcsystems.amanda.web.viewmodel.ToolbarCustomizeViewModel.afterCompose(ToolbarCustomizeViewModel.java:93)
  &gt;&gt;  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  &gt;&gt;  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  &gt;&gt;  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  &gt;&gt;  at java.lang.reflect.Method.invoke(Unknown Source)
  &gt;&gt;  at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111)
  </code></pre>
  
  <p>zul:</p>
  
  <pre><code>&lt;zk xmlns:x="xhtml" xmlns:zk="zk"&gt;
      &lt;window apply="org.zkoss.bind.BindComposer"
              viewModel="@id('vm') @init('com.csdcsystems.amanda.web.viewmodel.ToolbarCustomizeViewModel')" title="Customize Toolbar" height="600px"
          width="600px" closable="true" focus="true"&gt;
          &lt;borderlayout width="100%" height="100%" &gt;
              &lt;north border="none"&gt;
                  &lt;hlayout&gt;
                      &lt;space width="5px" /&gt;
                      &lt;x:table border="0"&gt;
                          &lt;x:tr&gt;
                              &lt;x:td&gt;
                                  &lt;label
                                      value="Display label along with icons" sclass="group-header" /&gt;
                              &lt;/x:td&gt;
                              &lt;radiogroup
                                  selectedItem="@bind(vm.displayIcon)"&gt;
                                  &lt;x:td valign="center"&gt;
                                      &lt;radio label="Display" 
                                          value="display" focus="@load(vm.displayFocus)"/&gt;
                                  &lt;/x:td&gt;
                                  &lt;x:td valign="center"&gt;
                                      &lt;radio label="Hide" value="hide" focus="@load(vm.hideFocus)"/&gt;
                                  &lt;/x:td&gt;
                              &lt;/radiogroup&gt;
                          &lt;/x:tr&gt;
  
                      &lt;/x:table&gt;
                  &lt;/hlayout&gt;
              &lt;/north&gt;
              &lt;center border="none"&gt;
                  &lt;hlayout style="padding: 10px;" hflex="1" vflex="1"&gt;
                      &lt;separator /&gt;
                      &lt;listbox model="@bind(vm.haveList)" droppable="true"
                          onDrop="@command('dropToHaveList',item=event.dragged.attributes.item)"
                          hflex="1" vflex="1"&gt;
                          &lt;listhead&gt;
                              &lt;listheader
                                  label="${a:resource('ValidUserSetup:LABEL_HAVE')}" /&gt;
                          &lt;/listhead&gt;
                          &lt;template name="model" var="tbaritem"&gt;
                              &lt;listitem draggable="true" droppable="true"
                                  label="@load(tbaritem.name)" attributes.item="@load(tbaritem)"
                                  onDrop="@command('insertToHaveList',item=event.dragged.attributes.item, base=tbaritem)"&gt;
                                  &lt;listcell
                                      image="@load(tbaritem.imagePath)" /&gt;
                              &lt;/listitem&gt;
                          &lt;/template&gt;
                      &lt;/listbox&gt;
                      &lt;separator /&gt;
                      &lt;listbox model="@bind(vm.availableList)"
                          droppable="true"
                          onDrop="@command('dropToAvailableList',item=event.dragged.attributes.item)"
                          hflex="1" vflex="1" multiple="true"&gt;
                          &lt;listhead&gt;
                              &lt;listheader
                                  label="${a:resource('ValidUserSetup:LABEL_AVAILABLE')}" /&gt;
                          &lt;/listhead&gt;
                          &lt;template name="model" var="tbaritem"&gt;
                              &lt;listitem draggable="true" droppable="true"
                                  label="@load(tbaritem.name)" attributes.item="@load(tbaritem)"
                                  onDrop="@command('insertToAvailableList',item=event.dragged.attributes.item, base=tbaritem)"&gt;
                                  &lt;listcell
                                      image="@load(tbaritem.imagePath)" /&gt;
                              &lt;/listitem&gt;
                          &lt;/template&gt;
                      &lt;/listbox&gt;
                      &lt;separator /&gt;
                  &lt;/hlayout&gt;
              &lt;/center&gt;
              &lt;south border="none"&gt;
                  &lt;hlayout style="padding: 10px;"&gt;
                      &lt;space width="35px" /&gt;
                      &lt;button
                          label="${a:resource('ValidUserSetup:CB_HAVEALL')}"
                          onClick="@command('haveAll')" /&gt;
                      &lt;space width="15px" /&gt;
                      &lt;button
                          label="${a:resource('ValidUserSetup:CB_HAVENONE')}"
                          onClick="@command('haveNone')" /&gt;
  
                      &lt;space width="125px" /&gt;
                      &lt;button onClick="@command('save')" label="Save"/&gt;
                      &lt;space width="15px" /&gt;
                      &lt;button onClick="@command('cancel')" label="Cancel" /&gt;
                  &lt;/hlayout&gt;
              &lt;/south&gt;
          &lt;/borderlayout&gt;
      &lt;/window&gt;
  &lt;/zk&gt;
  </code></pre>
  
  <p>Here's Java code :</p>
  
  <pre><code>int toolsCount =AbcdConstants.toolbar_image.length;
                  int maxtool = AbcdConstants.S_TOOLBAR.length();
                  LOGGER.debug("toolbar not set for user group");
                  for (int index = 0, tbarIndex = 1; index &lt; toolsCount; index++) {
                      if (AbcdConstants.toolbar_name[1][index].equalsIgnoreCase("true") &amp;&amp; tbarIndex &lt; maxtool) {
                          if (AbcdResourceBundle.get("TOOLBAR_EXECUTIVE_MONITOR").equals(
                                  AbcdResourceBundle.get(AbcdConstants.toolbar_name[0][index]))
                                  &amp;&amp; (module.charAt(28) == 'N' || !AbcdLicence.get().isExecutiveMonitorEnabled())) {
                              continue;
                          }
                          imageName.add(AbcdConstants.toolbar_image[index]);
                          iconDisplayName.add(AmandaResourceBundle.get(AbcdConstants.toolbar_name[0][index]));
                          toolbarIndexValue.add(tbarIndex, String.valueOf(tbarIndex + 2));
                          ToolbarItem thisitem = new ToolbarItem();
                          thisitem.setItemIndex((tbarIndex + 2));
                          thisitem.setName(AbcdResourceBundle.get(AbcdConstants.toolbar_name[0][index]));
                          thisitem.setImagePath(IMAGE_PATH + AbcdConstants.toolbar_image[index].toLowerCase());
                          allItems.add(thisitem);
                      }
                      tbarIndex += 2;
                  }
  </code></pre>
  
  <p>The exception occurs in this line :</p>
  
  <pre><code>toolbarIndexValue.add(tbarIndex, String.valueOf(tbarIndex + 2));
  </code></pre>
  
  <p>Can anyone tell me how can I resolve this issue ?</p>
  
  <p>Thanks</p>