I want to map the buttons to an array of buttons and the code has no errors while compiling but there is force close when i run it:
Button buttons[];
@Overr
Try the following code:
private int objectLength = 9; //Array elements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_board_view);
Button[] buttons = new Button[objectLength];
buttons[0] = (Button)findViewById(R.id.buttonOne);
buttons[1] = (Button)findViewById(R.id.buttonTwo);
buttons[2] = (Button)findViewById(R.id.buttonThree);
buttons[3] = (Button)findViewById(R.id.buttonFour);
buttons[4] = (Button)findViewById(R.id.buttonFive);
buttons[5] = (Button)findViewById(R.id.buttonSix);
buttons[6] = (Button)findViewById(R.id.buttonSeven);
buttons[7] = (Button)findViewById(R.id.buttonEight);
buttons[8] = (Button)findViewById(R.id.buttonMid);
}