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程序出错?


- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01