I am programming a tic-tac-toe android app, and I'm trying to use a for loop to make all the buttons in the array I put them in the same size.
However, when I put this line of code in to do that:
for (int count = 0; count < 9; count++){
board[count].Height(ht);
}
The app crashes when I try to run it, without explanation.
What is going on?
Here is the entire code for reference:
package tictacstartns;
import com.google.devtools.simple.runtime.components.android.Button;
import com.google.devtools.simple.runtime.components.Component;
import com.google.devtools.simple.runtime.components.HandlesEventDispatching;
import com.google.devtools.simple.runtime.components.android.Form;
import com.google.devtools.simple.runtime.components.android.HorizontalArrangement;
import com.google.devtools.simple.runtime.components.android.Label;
import com.google.devtools.simple.runtime.events.EventDispatcher;
public class TicTacStartNS extends Form implements HandlesEventDispatching {
private Button btnOne;
private Button btnTwo;
private Button btnThree;
private Button btnFour;
private Button btnFive;
private Button btnSix;
private Button btnSeven;
private Button btnEight;
private Button btnNine;
private Button btnXOchanger;
private Button btnReset;
private Button btnClearScore;
private Label lblTurn;
private Label lblSpace;
private Label lblXWins;
private Label lblXWinsCount;
private Label lblOWins;
private Label lblOWinsCount;
private Label lblCatsGame;
private Label lblCatsGameCount;
int ht = 75;
int wd = 75;
float fs = 50.0f;
boolean xGoesNow = true;
Button board[]= {btnOne,btnTwo,btnThree,btnFour,btnFive,btnSix,btnSeven,btnEight,btnNine};
void $define() {
HorizontalArrangement hr = new HorizontalArrangement(this);
btnOne = new Button(hr);
btnTwo = new Button(hr);
btnThree = new Button (hr);
hr = new HorizontalArrangement(this);
board[3] = new Button(hr);
board[4] = new Button(hr);
board[5] = new Button(hr);
hr = new HorizontalArrangement(this);
board[6] = new Button(hr);
board[7] = new Button(hr);
board[8] = new Button(hr);
for (int count = 0; count < 9; count++){
board[count].Height(ht);
}
EventDispatcher.registerEventForDelegation(this, "JavaBridge", "Click");
}
@Override
public boolean dispatchEvent(Component component, String id, String eventName,
Object[] args) {
if (component.equals(btnOne) && eventName.equals("Click")) {
btnOne.Text(xGoesNow?"X":"O");
xGoesNow = (xGoesNow?false:true);
return true;
} else if (component.equals(btnTwo) && eventName.equals("Click")) {
btnTwo.Text(xGoesNow?"X":"O");
xGoesNow = (xGoesNow?false:true);
return true;
} else if (component.equals(btnThree) && eventName.equals("Click")) {
btnThree.Text(xGoesNow?"X":"O");
xGoesNow = (xGoesNow?false:true);
return true;
}
return false;
}
}