正如标题所示。这些不是来自R.java的错误被删除 - 它仍然存在于一个部分中。但是对于项目中间的几百行代码,存在随机错误,这些错误没有一致性。例如,在switch-case中的一个案例中出现Syntax error on token "case", assert expected
错误,但所有其他案例都很好,rnd1
,一个本地随机变量,据说是重复的,但它是&#39}不是。我重新启动了Eclipse并无数次清理了项目。有谁知道如何摆脱错误?
代码哪些错误:
public void attack1Method() {
switch (rand1) {
case 1:
if (minion1Hp > 0) {
minion1Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack1);
}
}, 472);
}
});
minion1Bar();
}
if (minion1Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
switch (rand6) {
case 1:
attack1.startAnimation(m1attack1);
break;
case 2:
attack1.startAnimation(m1attack2);
break;
case 3:
attack1.startAnimation(m1attack3);
break;
case 4:
attack1.startAnimation(m1attack4);
break;
case 5:
attack1.startAnimation(m1attack5);
break;
case 6:
attack1.startAnimation(m1attack6);
break;
case 7:
attack1.startAnimation(m1attack7);
break;
}
}
});
}
}
break;
case 2:
if (minion2Hp > 0) {
minion2Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack2);
}
}, 728);
}
});
minion2Bar();
}
if (minion2Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
}
break;
case 3:
if (minion3Hp > 0) {
minion3Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack3);
}
}, 900);
}
});
minion3Bar();
}
if (minion3Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
}
break;
case 4:
if (minion4Hp > 0) {
minion4Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack4);
}
}, 288);
}
});
minion4Bar();
}
if (minion4Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
}
break;
case 5:
if (minion5Hp > 0) {
minion5Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack5);
}
}, 500);
}
});
minion5Bar();
}
if (minion5Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
}
break;
case 6:
if (minion6Hp > 0) {
minion6Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack6);
}
}, 628);
}
});
minion6Bar();
}
if (minion6Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
}
break;
case 7:
if (minion7Hp > 0) {
minion7Hp--;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
public void run() {
attack1.startAnimation(m1attack7);
}
}, 868);
}
});
minion7Bar();
}
if (minion7Hp <= 0) {
Random rnd1 = new Random();
if (waveNum == 3 || waveNum == 6 || waveNum == 9) {
rand1 = cannonNum[rnd1.nextInt(cannonNum.length)];
} else {
rand1 = minionNum[rnd1.nextInt(minionNum.length)];
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
switch (rand6) {
case 1:
attack1.startAnimation(m1attack1);
break;
case 2:
attack1.startAnimation(m1attack2);
break;
case 3:
attack1.startAnimation(m1attack3);
break;
case 4:
attack1.startAnimation(m1attack4);
break;
case 5:
attack1.startAnimation(m1attack5);
break;
case 6:
attack1.startAnimation(m1attack6);
break;
case 7:
attack1.startAnimation(m1attack7);
break;
}
}
});
}
}
break;
}
if (attack1Stop == 0 && appRunning == 1) {
attack1Thread.postDelayed(attack1Runnable, 1500);
}
}
它为我提供了Duplicate local variable rnd1
和Duplicate local variable rnd1
等错误。代码之前工作正常,但现在整个方法都出错了。偶尔会出现一些Syntax error on token "}", delete this token
错误。
所有帮助表示赞赏。
答案 0 :(得分:0)
你能发布一些错误的例子吗?如果我不知道错误发生在哪里,我无法帮助你。
对于令牌“case”上的“语法错误,断言预期的”错误,当你错过了某个开放括号,近括号或分号时,Eclipse有时会显示此错误。尝试在有问题的案例之前查看案例以找到任何遗漏的字符。
如果您还没有尝试过,请在文件中搜索“rnd1”,看看是否在其他任何地方宣布过。