私はtic-tac-toeandroidアプリをプログラミングしており、forループを使用して、配列内のすべてのボタンを同じサイズにしようとしています。
ただし、これを行うためにこのコード行を挿入すると、次のようになります。
for (int count = 0; count < 9; count++){
board[count].Height(ht);
}
説明なしで実行しようとすると、アプリがクラッシュします。
何が起こっている?
参考のためにコード全体を次に示します。
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;
}
}