How to fix quot;cannot find symbol errorquot; for my program?(如何修复“找不到符号错误为我的程序?)
问题描述
我很难找到为什么我不断收到此消息:
I am struggling to find why I keep receiving this message:
Integer.java:13: error: cannot find symbol
num = Integer.parseInt(numStr);
^
symbol: method parseInt(String)
location: class Integer
Integer.java:16: error: cannot find symbol
num2 = String.parseInt(numStr2);
^
symbol: method parseInt(String)
location: class String
2 errors
我错过了什么吗?谢谢.
Is there something I missed? Thanks.
import javax.swing.JOptionPane;
public class Integer
{
public static void main (String[] args)
{
String numStr, numStr2, sum, product;
int num, num2, again;
do
{
numStr = JOptionPane.showInputDialog("Enter an integer: ");
num = Integer.parseInt(numStr);
numStr2 = JOptionPane.showInputDialog("Enter another integer: ");
num2 = Integer.parseInt(numStr2);
sum = "The sum is " + ((num + num2));
product = " and the product is " + ((num * num2));
JOptionPane.showMessageDialog(null, sum);
again = JOptionPane.showConfirmDialog(null, "Do Another?");
}
while (again == JOptionPane.YES_OPTION);
}
}
推荐答案
你应该把你的类重命名为另一个名字,也许叫它IntegerMachine"而不是Integer".Java 已经有一个名为Integer"的本机类,通过命名您自己的类,这意味着您调用的不是您想要的 java.lang.Integer.parseInt(string),而是调用 .Integer.parseInt(),后者不存在.
You should rename your class to another name, perhaps call it "IntegerMachine" and not "Integer". Java already has a native class with the name "Integer", and by naming your own class the same would mean that instead of calling java.lang.Integer.parseInt(string), which you intended, you are calling .Integer.parseInt(), for which the latter does not exist.
这篇关于如何修复“找不到符号错误"为我的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何修复“找不到符号错误"为我的程序?
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01