1

For some reason javac can't compile Integer.parseInt(). I tried several programs that have parseInt in them and they don't work so I wrote up a simple little program to test whether the problem is parseInt or something else in the programs. Here's the test program I wrote:

public class Test
{
public static void main(String[] args)
{
int a = Integer.parseInt(args[0]);  
System.out.println(a);

}
}

Even with the program above, I still got a compiler error saying: "error: cannot find symbol a = Integer.parseInt();" with an arrow point to the . between Integer and parse. I've tried running the program with Double.parseDouble() and it works just fine. Any ideas as to why I'm getting this error?

3
  • 2
    This is not the code that got that error. Commented Oct 15, 2013 at 20:50
  • 4
    If that's not compiling, then someone hacked your javac. Commented Oct 15, 2013 at 20:51
  • 9
    Did you make your own class called Integer by chance? Commented Oct 15, 2013 at 20:52

2 Answers 2

2

Java imports the java.lang package for you. All the classes in that package are therefore available to your program without needing to use an import statement. If however you have declared a class called Integer in your package (the default package), then you are shadowing the Integer in java.lang.

You can use the fully qualified name of the class instead

java.lang.Integer.parseInt(args[0]);

Or create your own static parseInt(String) method in your custom Integer class. That will make the program compile. Make sure that it does what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

Or create your own static parseInt(String) method in your custom Integer class I would highly advise against making a class named Integer to begin with, nevermind matching the method names so that we catch less compile-time errors.
1

Instead of Integer.parseInt(), try:

java.lang.Integer.parseInt(args[0]);

This will ensure you definitely use the correct Integer class in java.lang - if that doesn't work then there's something seriously wrong with your environment. If it does then you must have another class called Integer somewhere that you're implicitly referring to instead of the java.lang.Integer class.

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.