3

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);
    }
}
10
  • 2
    Are you importing the Integer class correctly ? Commented Dec 23, 2014 at 18:13
  • 7
    @OneMoreError You shouldn' have to import Integer since it is in java.lang which is implicitly imported. Maybe he has his own Integer class? Commented Dec 23, 2014 at 18:15
  • 1
    Your code seems to work in my IDE. Can you please paste the imports in your code ? Commented Dec 23, 2014 at 18:18
  • 4
    The only possible explanation is that you have a different Integer class available at your class path... please confirm, that there is nothing else next to your PassArg.java file (namely no Integer.java mess). Commented Dec 23, 2014 at 18:21
  • 1
    @jamesFog Just rename it Commented Dec 23, 2014 at 18:28

3 Answers 3

6

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
Sign up to request clarification or add additional context in comments.

Comments

4

You probably have a class "Integer" in your src folder that is overiding the default Integer Java Class. Look at your import statements.

Comments

0

It has to be something with your JDK build path, try to verify the path to your JDK by right clicking your project->properties->build path and make sure it's pointing to your JDK path. Also, try cleaning your project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.