如何修复“找不到符号错误"?为我的程序? [英] How to fix "cannot find symbol error" for my program?

查看:271
本文介绍了如何修复“找不到符号错误"?为我的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找为什么继续收到此消息的原因:

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"的本机类,通过命名您自己的类,这将意味着您将调用.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.

这篇关于如何修复“找不到符号错误"?为我的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆