ANDROID: Adding items from an arraylist to an AlertDialog
<p>I am trying to add the contents of my array list to an AlertDialog, but it comes up with error:</p>

<pre><code>java.lang.IllegalStateException: Could not execute method of the activity
</code></pre>

<p>Here is my code snippet that I am having problems with:</p>

<pre><code> public void ShowOnlineUserDialog(){
     CharSequence[] users = {_onlineUsers.get(1), _onlineUsers.get(2),    _onlineUsers.get(3), _onlineUsers.get(4)};
     AlertDialog.Builder onlineUser = new AlertDialog.Builder(this);
     onlineUser.setTitle("Online Users");
     onlineUser.setItems(users, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            System.out.println("User clicked!");

        }
    });
     onlineUser.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();

        }
    });
     onlineUser.show();
 }
</code></pre>

<p>Moreover, is there a more efficient way of adding to the alertbox, for loop maybe? I'm sorry but my lack of knowledge in arrays fails me.</p>

<p>Any help would be amazing! Thank you!</p>

<p>EDIT: If I set my code out this way:</p>

<pre><code> String user1 = _onlineUsers.get(1);
     String user2 = _onlineUsers.get(0);

     CharSequence[] users = {user1, user2};
</code></pre>

<p>It works perfectly, but I would like to find a more efficient way?</p>
