How to fix “cannot find symbol error” for my program?

前端 未结 2 1738
温柔的废话
温柔的废话 2021-01-26 10:28

I am struggling to find why I keep receiving this message:

Integer.java:13: error: cannot find symbol
         num = Integer.parseInt(numStr);
                           


        
相关标签:
2条回答
  • 2021-01-26 10:37

    @Ricardo Desu Perez

    change your below line

    num = Integer.parseInt(numStr);
    

    to following

    num = java.lang.Integer.parseInt(numStr);
    

    if you intend to call default parseInt method in Integer class else write your own version of parseInt(String) method

    0 讨论(0)
  • 2021-01-26 10:43

    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.

    0 讨论(0)
提交回复
热议问题