Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer parseInt method not found

Tags:

java

I am trying to this code in which test out a simple method. In which you use a method which receives argument. The problem that is happening is with Integer parse int method.

The command prompt gives an error which is.

java:24:error:cannot find symbol

cholo=Integer.parseInt("123");

             ^
symbol: method parseInt(String)

location: class Integer

1 error

I am not sure what is causing this.

//Passing arguments in java

//this program demonstrates a method with a paramter

public class PassArg {
    public static void main(String[] args) {
        int x = 10;
        int k;
        int cholo;
        System.out.println(" I am passing values to displayValue ");


        displayValue(5);
        displayValue(x);
        displayValue(x * 4);
        k = 14;
        displayValue(14);
        cholo = Integer.parseInt("123");
        displayValue(cholo);
        System.out.println("now I am back in the main");
    }

    public static void displayValue(int num) {
        System.out.println("the value is " + num);
    }
}
like image 563
james Fog Avatar asked Sep 26 '26 03:09

james Fog


1 Answers

The only explanation I can think of is you have your own Integer class which you are getting (and not java.lang.Integer). Rename your other Integer class, or use the full qualified class name like

int cholo = java.lang.Integer.parseInt("123");
System.out.println(cholo);

Output is

123
like image 120
Elliott Frisch Avatar answered Sep 27 '26 17:09

Elliott Frisch