Reputation: 11
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?
Upvotes: 1
Views: 2008
Reputation: 279960
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.
Upvotes: 2
Reputation: 72284
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.
Upvotes: 1