简体   繁体   English

为什么Eclipse无法识别Java库?

[英]Why is Eclipse not recognizing Java libraries?

Possibly I am misunderstanding the problem, so I may be asking the wrong question. 可能我误解了这个问题,所以我可能会问错问题。 I am using Mac OSX 10.8.3 and I am creating an applet in eclipse. 我正在使用Mac OSX 10.8.3,并且正在eclipse中创建一个applet。 When I try using import java.* where * is awt , applet , util , etc. 当我尝试使用import java.* ,其中*awtappletutil等。

Eclipse shows errors, basically behaving as if it does not recognize the Java libraries. Eclipse显示错误,基本上表现为似乎无法识别Java库。 In the preferences I have the Java SE 6 JRE selected. 在首选项中,我选择了Java SE 6 JRE。 I tried lowering the compiler compliance level to 1.6 but it didn't seem to do anything. 我尝试将编译器的遵从性级别降低到1.6,但似乎没有任何作用。

For some of the classes I imported the code was written on a windows machine, but I don't see how that would matter. 对于我导入的某些类,代码是在Windows机器上编写的,但我认为那没有什么关系。 Any thoughts? 有什么想法吗?

Remove the imports, and then Eclipse should detect that the imports you need are not imported. 除去导入,然后Eclipse应该检测到您需要的导入没有被导入。 Then press CTRL + SHIFT + O to organize your imports, and Eclipse should automatically retrieve every import you need. 然后按CTRL + SHIFT + O来组织您的导入,Eclipse应该自动检索您需要的每个导入。

Also, you should never import more than you have to. 另外,您绝不应该进口过多的东西。 If import java.* even worked (which it never will), it would be a horrible practice, because then all those libraries have to be loaded into memory (even the ones you don't need). 如果import java.*甚至可以工作(它永远都不会),那将是一个可怕的做法,因为那样的话,所有这些库都必须加载到内存中(甚至不需要的库)。 To conserve memory space, avoid using * with imports (Eclipse does this when you organize the imports). 为了节省内存空间,请避免在导入中使用* (在组织导入时Eclipse会这样做)。

If you import java.* you only import all classes, interfaces, and so on, which are in the java folder. 如果导入java.* ,则仅导入java文件夹中的所有类,接口等。 To import classes out of utils you will have to import java.utils.* . 要从utils中导入类,您必须导入java.utils.* The * is does not work recursively. *是不能递归工作的。 It's better practise to just import classes that you really need. 更好的做法是只导入您真正需要的类。 Normally Eclipse suggested automated import statement generations. 通常,Eclipse建议自动生成导入语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM