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程序出错?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
