A very strange for loop bug in Java for Android?
<p>I'm trying to alter the attributes of an array of Buttons, however I am getting some very strange errors. I am trying to loop through the buttons to edit the height attribute of each one, however when I set up a for loop (i=0; i&lt;3; i++), buttonSkater[i].setHeight(buttonHeight); the result seems to be that 9 buttons are being altered! And when I set i&lt;14 (there are 14 buttons), then the application crashes with a NullPointerException. </p>

<pre><code>package com.rollerderby.lineuptracker;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;


public class Setup extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.setup); 

        Button[] buttonSkater = new Button[14]; 
        buttonSkater[0] = (Button) findViewById(R.id.buttonSkater1);
        buttonSkater[1] = (Button) findViewById(R.id.buttonSkater2);
        buttonSkater[2] = (Button) findViewById(R.id.buttonSkater3);

        int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); 
        int buttonHeight = (screenHeight-60)/14; 


        for(int i=0; i&lt;14; i++)
        {
            buttonSkater[i].setHeight(buttonHeight);
        }


    }
}
</code></pre>

<p>It seems a very strange error... Am I missing something obvious? </p>

<p>(Sizing the array wrong by creating it with space for new Buttons?) </p>
