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程序出错?
基础教程推荐
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- JPA惰性列表上的流 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
