对于我介绍Java的最后一个项目,我决定做一个Mastermind Peg Game。netbeans中的“找不到符号”错误(Java Netbeans 6.5)
这是提交按钮代码:
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
Integer guess1, guess2, guess3, guess4;
Integer rightnumber = 0, rightposition = 0;
guess1 = Integer.parseInt (firstInput.getText());
guess2 = Integer.parseInt (secondInput.getText());
guess3 = Integer.parseInt (thirdInput.getText());
guess4 = Integer.parseInt (fourthInput.getText());
//Values are compared to the actual guess.
//(THIS IS WHERE I GET THE FOLLOWING ERROR:
//"cannot find symbol, symbol : variable answerdigit,
//location: class finalproject.Singleplayer"
if (guess1 == answerdigit[0]);
{
rightposition = rightposition + 1;
}
}
这是启动按钮。这里生成4位数的答案/代码。
private void startButtonActionPerformed(java.awt.event.ActionEvent evt)
{
// Declare variables for 4 digit answer, guess for each number
Integer one, two, three, four;
//Generate random number between 1 and 6 for each digit in the answer
int[] answerdigit = new int[4];
for(int i=0;i<4;i++)
{
answerdigit[i]=(int)(Math.random()*6+1);
}
}
我得到一个错误:
cannot find symbol, symbol : variable answerdigit, location: class finalproject.Singleplayer
我不明白是什么错误意味着。
您使用的变量,它不是方法的范围内存在submitButtonActionPerformed(...)。阅读Java变量范围,了解错误的含义:http://www.java-made-easy.com/variable-scope.html –