Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Eclipse (for Android): The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

I am trying to run an Android project that someone else has created. I have opened the project in Eclipse as:

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

Here are the first two lines of one of Java files:

package aa.bb.cc;

import java.io.File;

There is red cross sign at the beginning of these lines and when I hold the mouse over them I get this message for the first line: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files anfd for the second line get this message: The import java.net cannot be resolved.

What is the reason and how can I resolve these error messages?

Thanks.

like image 924
TJ1 Avatar asked Nov 05 '12 02:11

TJ1


People also ask

What does string Cannot be resolved to a type mean in Java?

Java is a case-sensitive language, that is, uppercase and lowercase letters are treated differently. Here “string” is not resolved because there is no class or data type named “string”.

How do I resolve an error in eclipse?

You have open eclipse. ini file and change -vm path to correct JDK location. In my case it's /Library/Java/JavaVirtualMachines/jdk1.


2 Answers

Do one more step before running:

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

Click OK and then clean-build (Project -> Clean & Project -> Build All or Ctrl+B) your project. It should be fine.

like image 121
Yogendra Singh Avatar answered Sep 18 '22 17:09

Yogendra Singh


This is an annoying Eclipse Bug which seems to bite now and then. See http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html for a possible solution, otherwise try the following;

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.
like image 36
Shaishav Jogani Avatar answered Sep 16 '22 17:09

Shaishav Jogani