Eclipse 中的错误(适用于 Android):无法解析 java.lang.String 类型。它从所需的.class文件中间接引用

2022-09-04 06:32:14

我正在尝试运行其他人创建的Android项目。我已经在Eclipse中打开了这个项目:

File --> New --> Project --> Android Project from existing code

以下是其中一个 Java 文件的前两行:

package aa.bb.cc;

import java.io.File;

这些行的开头有红色的十字符号,当我将鼠标悬停在它们上面时,我收到第一行的此消息:第二行的anfd获取此消息:。The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class filesThe import java.net cannot be resolved

原因是什么,我该如何解决这些错误消息?

谢谢。


答案 1

在运行之前再执行一个步骤:

Right Click(Project) -> Properties -> Java Build Path -> Libraries -> 
                                          Add Library -> Select the Java Library

单击“确定”,然后清理生成 ( & 或 ) 你的项目。应该没问题。Project -> CleanProject -> Build AllCtrl+B


答案 2

这是一个令人讨厌的Eclipse Bug,似乎时不时地咬人。请参阅 http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html 以获取可能的解决方案,否则请尝试以下操作;

Close the project and reopen it.

Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)

OR

Delete and Re-import the project and if necessary do the above steps again.

推荐