IndexOutOfBoundsException in ArrayAdapter
<p>I got a trivial code involving a <code>ListView</code> and a <code>ArrayAdapter</code> which throws a IndexOutOfBoundsException on some devices. The problem is: I do not know how this Exception occurs, I only get the stacktraces from the Developer Console of Android.</p>

<p>The reduced code example is shown below. How can the <code>getItem</code> operation of the <code>ArrayAdapter</code> fail for the <code>position</code> element? The <code>ArrayAdapter</code> is never changed, there is no other method in the <code>Activity</code>.</p>

<p><strong>I know what a <code>IndexOutOfBoundsException</code> is, I know that I can prevent it by checking the length first. But I'm curious: How can this Exception happen here? How can someone click on a event which does not exist in the datastructure?</strong></p>

<p>Reduced code:</p>

<pre><code>public class EventListActivity extends Activity {
    public void onStart() {
        final ListView listview = new ListView(this);
        final Event[] events = [Retrieve a Array from somewhere]
        final ArrayAdapter&lt;Event&gt; a = new ArrayAdapter&lt;Event&gt;(this, R.layout.eventlistitem, events);
        listview.setAdapter(a);
        listview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                Event event = a.getItem(position);
                                ^^^^^^^ throws Exception
            }
        });
</code></pre>

<p>Exception:</p>

<pre><code>java.lang.IndexOutOfBoundsException
at java.util.Arrays$ArrayList.get(Arrays.java:75)
at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
at xxx.EventListActivity$3.onItemClick(EventListActivity.java:130)
</code></pre>
