-1
我正在編寫一個tic-tac-toe android應用程序,並且我正在嘗試使用for循環來將所有按鈕放在我將它們放在相同大小的數組中。Android應用崩潰沒有解釋。
然而,當我把這個行代碼中做到這一點:
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;
}
}
哦,有一個解釋。看看logcat的堆棧跟蹤並將其發佈到此處。 – 2013-03-07 20:29:31