title: Android: Snackbar gives ArrayIndexOutOfBoundsException
body: <p>the code that seems to give the exception is the following:</p>
  
  <pre><code>Snackbar.make(findViewById(R.id.content_main), "E' necessario abilitare il GPS per aggiornare la lista", Snackbar.LENGTH_INDEFINITE)
          .setAction("ATTIVA", new View.OnClickListener() {
  
               @Override
               public void onClick(View v) {
  
                  Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                  startActivity(intent);
               }
  }).show();
  </code></pre>
  
  <p>I say so because I tried debugging the application and it works only removing this part of the code.</p>
  
  <p>Here's the error log:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: d.g.movida, PID: 22151
  java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
      at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
      at java.util.ArrayList.get(ArrayList.java:308)
      at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:848)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1197)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
      at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
      at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
      at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3193)
      at android.view.View.layout(View.java:17938)
      at android.view.ViewGroup.layout(ViewGroup.java:5812)
      at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2666)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2367)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7403)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
      at android.view.Choreographer.doCallbacks(Choreographer.java:695)
      at android.view.Choreographer.doFrame(Choreographer.java:631)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:158)
      at android.app.ActivityThread.main(ActivityThread.java:7229)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  </code></pre>
  
  <p>The only moments when I use an ArrayList are when I initialize it:</p>
  
  <pre><code>ArrayList&lt;CustomLVArray&gt; retrievedData;
  ListAdapter listAdapter;
  ListView listView;
  
  ....
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      ....
  
      retrievedData = new ArrayList&lt;&gt;();
      listView = (ListView) findViewById(R.id.content_main);
  
      listAdapter = new CustomListViewAdapter(this, retrievedData);
      listView.setAdapter(listAdapter);
  
      listView.setOnScrollListener....
  </code></pre>
  
  <p>and when i add stuff to it:</p>
  
  <pre><code>CustomLVArray message = new CustomLVArray("Title", "subtitle", "Lorem ipsum dolor sit amet ipsum dolor sit amet ipsum dolor sit amet ipsum dolor sit amet", getResources().getDrawable(R.drawable.ic_menu_camera));
  
          retrievedData.clear();
  
          for (int i = 0; i &lt;= 10; i++) {
  
              retrievedData.add(message);
          }
  </code></pre>