title: IndexOutOfBoundsException in expandable listview
body: <p>According to this great answer <a href="https://stackoverflow.com/questions/5068668/android-expandablelistview-with-checkbox-controlling-checked-state">Android ExpandableListView with Checkbox, Controlling checked state</a> i made my class but i get an error to LogCat ArrayList.IndexOutOfBoundsException</p>
  
  <p>mMyClass</p>
  
  <pre><code>public ArrayList&lt;String&gt; groups;
  public ArrayList&lt;ArrayList&lt;ArrayList&lt;String&gt;&gt;&gt; childs;
  ..........
  ArrayList &lt; ArrayList &lt; Integer &gt;&gt; check_states =new ArrayList &lt; ArrayList &lt; Integer&gt;&gt;();
  
  public class myExpandableAdapter extends BaseExpandableListAdapter {     
  private ArrayList&lt;String&gt; groups;
  private ArrayList&lt;ArrayList&lt;ArrayList&lt;String&gt;&gt;&gt; children;
  private final Context context ;
  
  public myExpandableAdapter(Context context,ArrayList&lt;String&gt; groups, ArrayList&lt;ArrayList&lt;ArrayList&lt;String&gt;&gt;&gt; children) {
   this.context = context;
   this.groups = groups;
   this.children = children; }
  
  public void setChildrenAndValues(ArrayList&lt; ArrayList&lt; ArrayList&lt; String&gt;&gt;&gt; c) {
      this.children = c;
  
      //initialize the states to all 0;
      for(int i = 0; i &lt; c.size(); i++) {
  
          ArrayList&lt;Integer&gt; tmp = new ArrayList&lt;Integer&gt;();
          for(int j = 0; j &lt; c.size(); j++) {
              tmp.add(0);
          }
          check_states.add(tmp);
      }
  }
  
  @Override
  public boolean areAllItemsEnabled()
   {
       return true;
   }
  
  
  @Override
  public ArrayList&lt;String&gt; getChild(int groupPosition, int childPosition) {
   return children.get(groupPosition).get(childPosition);
   }
  
  @Override
   public long getChildId(int groupPosition, int childPosition) {
       return childPosition;
   }
  
  
  @Override
   public View getChildView(final int groupPosition, final int childPosition, boolean     isLastChild,View convertView, ViewGroup parent) {
  
  String child = (String) ((ArrayList&lt;String&gt;)getChild(groupPosition, childPosition)).get(0);
  
   if (convertView == null) {
       LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       convertView = infalInflater.inflate(R.layout.exp_list_child, null);
   }
  
   TextView childtxt = (TextView) convertView.findViewById(R.id.list_child1);
  
   childtxt.setText(child);   
   ///
   final View tick = findViewById(R.id.checkBox1);
   if(check_states.get(groupPosition).get(childPosition) == 1)
       tick.setVisibility(View.VISIBLE);
   else
       tick.setVisibility(View.GONE);
  
   convertView.setOnClickListener(new OnClickListener(){
       public void onClick(View v) {
           check_states.get(groupPosition).set(childPosition, 1);
          Toast.makeText(getApplicationContext(),""+ check_states, Toast.LENGTH_SHORT).show();
           tick.setVisibility(View.VISIBLE);
       }
   });
  
   return convertView;
   }
  
  @Override
   public int getChildrenCount(int groupPosition) {
       return children.get(groupPosition).size();
   }
  
  @Override
   public String getGroup(int groupPosition) {
       return groups.get(groupPosition);
   }
  
  @Override
   public int getGroupCount() {
       return groups.size();
   }
  
  @Override
   public long getGroupId(int groupPosition) {
       return groupPosition;
   }
  
  @Override
   public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
  
  String group = (String) getGroup(groupPosition);
  
  if (convertView == null) {
       LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       convertView = infalInflater.inflate(R.layout.exp_list_group, null);
   }
  
   TextView grouptxt = (TextView) convertView.findViewById(R.id.ListHeader);
  
   grouptxt.setText(group);
  
   return convertView;
   }
  
  @Override
   public boolean hasStableIds() {
       return true;
   }
  
  @Override
   public boolean isChildSelectable(int arg0, int arg1) {
       return true;
   }
  
  public void loadData(){
  groups= new ArrayList&lt;String&gt;();
  childs= new ArrayList&lt;ArrayList&lt;ArrayList&lt;String&gt;&gt;&gt;();
  
  int proion_id= getIntent().getExtras().getInt("proionId");
    int length = dbAdapter.getDetailsOf(proion_id).size();
  if(length &gt;0) {
  
  for (int i=0; i&lt; length; i++)
  {
      childs.add(new ArrayList&lt;ArrayList&lt;String&gt;&gt;());
      childs.get(i).add(new ArrayList&lt;String&gt;());
      childs.get(i).get(0).add("A");
      childs.get(i).add(new ArrayList&lt;String&gt;());
      childs.get(i).get(1).add("B");
      childs.get(i).add(new ArrayList&lt;String&gt;());
      childs.get(i).get(2).add("C");
  
  }
  
  } else 
  {childs.add(new ArrayList&lt;ArrayList&lt;String&gt;&gt;());
  childs.get(0).add(new ArrayList&lt;String&gt;());
  childs.get(0).get(0).add("NO");}
  
  }
  
      }
  </code></pre>
  
  <p>logcat</p>
  
  <pre><code>&gt; 07-03 03:42:57.168: E/AndroidRuntime(1644): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at java.util.ArrayList.get(ArrayList.java:308)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at com.techblogon.loginexample.ItemComments$myExpandableAdapter.getChildView(ItemComments.java:156)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.AbsListView.obtainView(AbsListView.java:2263)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.ListView.onMeasure(ListView.java:1175)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.View.measure(View.java:16497)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.Choreographer.doFrame(Choreographer.java:544)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.os.Handler.handleCallback(Handler.java:733)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.os.Handler.dispatchMessage(Handler.java:95)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.os.Looper.loop(Looper.java:136)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at java.lang.reflect.Method.invoke(Method.java:515)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  07-03 03:42:57.168: E/AndroidRuntime(1644):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Thanks in advance</p>