13

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.

4
  • 2
    Do you have JRE in class path configured? Commented Nov 5, 2012 at 2:56
  • 1
    How shall I do this configuration? Commented Nov 5, 2012 at 2:58
  • 2
    Right click on project---> Properties---> lib tab and see if have any installed there. Commented Nov 5, 2012 at 3:00
  • 2
    I added JRE System Library and the error went away. Thanks for the help. Commented Nov 5, 2012 at 3:17

2 Answers 2

30

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.

Sign up to request clarification or add additional context in comments.

7 Comments

When I try to do this I don't see "Java Library" in the list. here is what I see: Android ClassPath Container, JRE System Library, JUnit, Maven Managed Dependencies, User Library
Ok I added JRE System Library and the error went away. Thanks for the help.
@TJ1: I was typing that and you posted the comment. Good to know it worked.
thanks for the help. Now I have another error in a line: setContentView(R.layout.myFunc) that says R cannot be resolved to a variable, do you know what it could be?
@TJ1: Do you see any import statement in the top of your source file ending with R? I forgot to ask, have you added, android libraries also added in you classpath, as you just did for JRE?
|
2

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.

1 Comment

Try Netbeans instead of Eclipse? That sounds like some arrogant academic's opinion (which are worth tossing straight in the garbage right away, every time).Anyone reading this do not switch to NetBeans, if you make any switch switch to Android Studio.If you don't want Android Studio (or for WHEN op comes & says Android Studio wasn't out when he posted) go to IntelliJ.. Netbeans is not the correct move no matter what you want to do. I'm not going to back up this with any information other than that I am an experienced programmer,& I know when/where to prune the decision tree in many situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.