java 找不到符号:parseInt
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13435680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cannot find symbol: parseInt
提问by user1832679
I have allready compiled a few tiny programms in java and everything was fine. But my new code has any problem.
我已经用java编译了一些小程序,一切都很好。但是我的新代码有任何问题。
class myclass
{
public static void main (String[] args)
{
int x, y;
String s ="sssss";
x=args.length;
s= args[0].substring(1,2);
System.out.println("Num of args: "+x);
System.out.println("List of args:");
y = parseInt(s,5);
}
}
The compiler says:
编译器说:
e:\java>javac myclass.java
myclass.java:11: error: cannot find symbol
y = parseInt(s,5);
^ symbol: method parseInt(String,int) location: class myclass 1 error
e:\java>
The strange thing is that the compiler jumps over the method substring (as there is no problem) but the method parseInt seems to have any problem. y = parseInt(s); OR: y = parseInt("Hello"); --> Also the same compiler message.
奇怪的是,编译器跳过了方法子串(因为没有问题)但方法parseInt似乎有问题。y = parseInt(s); 或: y = parseInt("你好"); --> 也是同样的编译信息。
Or does the method not exist? docs.oracle-->Integersays it exists :)
或者方法不存在?docs.oracle-->Integer说它存在:)
It makes my really crazy as i don't know how to search for the error. I have checked the internet allready, i checked the classpath and the path...
这让我真的很疯狂,因为我不知道如何搜索错误。我已经检查了互联网,我检查了类路径和路径...
So it would be great if any expert could help me. :)
所以如果有专家可以帮助我就好了。:)
回答by PermGenError
回答by Frank
Your are trying to access a static method of the Integer
class
您正在试图访问的静态方法Integer
类
You must do:
你必须这样做:
y = Integer.parseInt(s,5);
回答by Pshemo
parseInt
is static method of Integer class. To invoke it you have to do one of few things:
parseInt
是Integer类的静态方法。要调用它,您必须执行以下操作之一:
invoke it on Integer class
Integer.parseInt(s, 5)
invoke it on Integer reference
Integer i = null;//yes reference can be even null in this case i.parseInt(s, 5);
OR to avoid first two options import that method using static import like
import static java.lang.Integer.parseInt;
. This way you can use that method likey = parseInt(s,5);
在 Integer 类上调用它
Integer.parseInt(s, 5)
在整数引用上调用它
Integer i = null;//yes reference can be even null in this case i.parseInt(s, 5);
或者为了避免前两个选项使用静态导入(如
import static java.lang.Integer.parseInt;
. 这样您就可以使用该方法,例如y = parseInt(s,5);