Why am I getting a quot;cannot find symbolquot; error in my java program when I compile?(为什么我会收到“找不到符号?编译时java程序出错?)
问题描述
我试图在我的代码末尾返回我的布尔变量 localFound 的值,但是当我编译时,我得到一个错误,说它找不到符号.我知道这是一个处理变量范围的错误,但我不知道如何修复它.如何让我的程序返回正确的值?谢谢.
I am trying to return the value of my boolean variable localFound at the end of my code but when I compile, I get an error that says it cannot find the symbol. I know this is an error that deals with the scope of the variable, but I do not know how to fix it. How do I get my program to return the correct value? Thanks.
public static boolean addIfNotEmpty(DvdTreeNode root, String movieToCommand) {
if (root == null) {
return false;
}
addIfNotEmpty(root.getRight(), movieToCommand);
if (root.getItem().getTitle().equalsIgnoreCase(movieToCommand)) {
root.getItem().addCopy();
System.out.println("You have added another copy of ""
+ movieToCommand
+ "" to the inventory.");
boolean localFound;
localFound = true;
}
addIfNotEmpty(root.getLeft(), movieToCommand);
return localFound;
} // end addIfNotEmpty
推荐答案
localFound
未在您的 return
语句的范围内定义.它只存在于您的 if
语句中.
localFound
is not defined in the scope of your return
statement. It only exists within your if
statement.
将声明移到 if
语句之外,并将其初始化为某个默认值,例如 false
.
Move the declaration outside of your if
statement, and initialize it to some default value, such as false
.
这篇关于为什么我会收到“找不到符号"?编译时java程序出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我会收到“找不到符号"?编译时java程序出错?
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01