我不明白发生了什么。我在" setOnClickListener"的开头有这个错误。 Eclipse所说的地方:"令牌上的语法错误,而是预期的AnnotationName"。而且,在最后一行,我有多个错误,上面写着:
- Syntax error, insert "}" to complete ClassBody
- Syntax error, insert "EnumBody" to complete EnumDeclaration
- Syntax error, insert ")" to complete SingleMemberAnnotation
- Syntax error, insert "enum Identifier" to complete
EnumHeaderName
然后我的代码是:
final Random random1 = new Random();
final Random random2 = new Random();
@SuppressLint("Recycle")
public class GameActivity extends Activity {
protected View buttonA;
protected View buttonB;
protected View buttonC;
protected View buttonD;
protected boolean flag = false;
protected boolean flag2 = false;
private Card[] cards;
final Button choice1 = (Button) findViewById(R.id.A);
final Button choice2 = (Button) findViewById(R.id.B);
final Button choice3 = (Button) findViewById(R.id.C);
final Button choice4 = (Button) findViewById(R.id.D);
final Button choice5 = (Button) findViewById(R.id.E);
int j = 0;
final Random random1 = new Random();
final Random random2 = new Random();
@SuppressLint({ "CutPasteId", "UseSparseArrays" })
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
findViewById(R.id.A);
Resources res = getResources();
String[] StringDeck = getResources().getStringArray(R.array.StringDeck);
int[] DeckDraw = getResources().getIntArray(R.array.DeckDraw);
final HashMap<String, Integer> DECK = new HashMap<String, Integer>();
for(int i = 0; i < DeckDraw.length; i++){
DECK.put(StringDeck[i], DeckDraw[i]);
}
final TypedArray Deck = res.obtainTypedArray(R.array.DeckDraw);
final ViewGroup groupButtons1 = (ViewGroup)findViewById(R.id.linearLayout1);
View v1;
final Button backgroundA = (Button) findViewById(R.id.A);
final Button backgroundB = (Button) findViewById(R.id.B);
final Button backgroundC = (Button) findViewById(R.id.C);
final Button backgroundD = (Button) findViewById(R.id.D);
final Button backgroundE = (Button) findViewById(R.id.E);
for(int i = 0; i < groupButtons1.getChildCount(); i++) {
v1 = groupButtons1.getChildAt(i);
if(v1 instanceof Button) v1.setOnClickListener(new Button.OnClickListener() {
backgroundA.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
if (j < 2){
randomInt1 = random1.nextInt(Deck.length());
drawableIDA = Deck.getResourceId(randomInt1, -1);
backgroundA.setBackgroundResource(drawableIDA);
j ++;
} else {
choice1.setEnabled(false);
}
}
});
所有进口都是正确的我不知道什么是错的。请帮帮我