Java 数组无法解析?这是构建路径问题吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25598254/
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
Arrays cannot be resolved? Is this a Build path issue?
提问by Ruslan Slobodyanik
When I type Arrays.sort(arr)
in Eclipse, I get this error Arrays cannot be resolved
and when I left click the red underlined Arrays
word I don't get import java.util.Arrays
as expected.
I installed JRE and JDK 1.8.0_20 and my Project build path is configured accordingly. What could be an issue?
当我Arrays.sort(arr)
在 Eclipse 中输入时,我收到此错误Arrays cannot be resolved
,当我左键单击红色下划线Arrays
字时,我没有得到import java.util.Arrays
预期的结果。我安装了 JRE 和 JDK 1.8.0_20,并相应地配置了我的项目构建路径。有什么问题?
采纳答案by óscar López
Manually add the following line at the beginning of the .java
file; if a package
declaration is present add it right after it, otherwise add it at the start of the file (or to keep things organized, add it in alphabetic order with respect to other imports):
在.java
文件的开头手动添加以下行;如果存在package
声明,则在其后立即添加它,否则将其添加到文件的开头(或为了使事情井井有条,请按相对于其他导入的字母顺序添加):
import java.util.Arrays;
Alternatively: type Ctrl+Shift+oto automatically import all the required dependencies.
或者:键入Ctrl+ Shift+o以自动导入所有必需的依赖项。
回答by Satish Chandra
I had the same issue in eclipse. I resolved it by changing the jdk compiler compliance level to 1.6 in the windows-->preferences-->java--->compiler.
我在日食中遇到了同样的问题。我通过在 windows-->preferences-->java--->compiler 中将 jdk 编译器合规级别更改为 1.6 来解决它。
回答by Pradeep Singh
If you want to call Arrays.sort(....) method. You need to call it inside the main method( or any method) of your program. Not in class level. Please make sure that.
如果要调用 Arrays.sort(....) 方法。您需要在程序的 main 方法(或任何方法)中调用它。不在班级。请确保。