Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import android packages cannot be resolved

My android application, built inside Eclipse, suddenly fails to build with dozens of errors. The most obvious are errors indicating that all the android imports cannot be resolved.

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

All of these are flagged as unresolvable. I've tried removing and re-adding the JRE System Library. I've tried cleaning and rebuilding. I've tried the "Quick fix" option to "Fix Project Setup..." but that simply responds with a dialog box that say...

"No proposals have been found to fix the unresolvable reference to 'android.app.Bundle'. Click here to manually configure the build path of project 'Silent Mode Toggle."

I'm new to Android development and this one has me completely stumped.

Thanks in advance for any help you can provide.

Rich

like image 930
Rich Wooley Avatar asked Jul 20 '12 17:07

Rich Wooley


4 Answers

It seems that your eclipse-workspace (or at least your Project) is broken somehow.

Have you moved your android-sdk/Project recently? If it's not an Android Project anymore, try to look at Preferences->Android for a valid android sdk-location.

If this is correct, try to open a complete new Workspace, and import your sources with File->import->Android Project from existing Source.

If this still doesn't help, make a new android Project and copy the sources manually inside your Project from outside Eclipse. Re-open Eclipse after that, and make a Project->clean

like image 165
Rafael T Avatar answered Sep 22 '22 17:09

Rafael T


What all the others said.

Specifically, I recommend you go to Project > Properties > Java Build Path > Libraries and make sure you have exactly one copy of android.jar referenced. (Sometimes you can get two if you're importing a project.) And that its path is correct.

Sometimes you can get the system to resolve this for you by clicking a different target SDK in Project > Properties > Android, then restoring your original selection.

like image 41
Sparky Avatar answered Sep 25 '22 17:09

Sparky


right click on project->properties->android->select target name as "Android 4.4.2" --click ok

since DocumentsContract is added in API level 19

like image 22
Angad Tiwari Avatar answered Sep 22 '22 17:09

Angad Tiwari


I just had the same problem after accepting a Java update--scores of build errors and android import not recognized. On checking the build path in Project=>Properties, I found that the check box for Android 4.3 had somehow gotten cleared. Checking it resolved all the import errors without my even having to restart the IDE or run a project clean.

like image 31
user382459 Avatar answered Sep 21 '22 17:09

user382459