Trouble Importing android-support-v4.jar

半腔热情 提交于 2019-12-13 04:58:56

问题


I am trying to do the tutorial Sample Code from the https://developers.google.com/maps/documentation/android/intro page.I import the google-play-services_lib just fine, then I import the /extras/google/google_play_services/samples/maps

At this point I have 2 errors:

The type android.support.v4.app.Fragment cannot be resolved. It is indirectly referenced from required .class files RetainMapActivity.java /MainActivity/src/com/example/mapdemo line 45 Java Problem

The project was not built since its build path is incomplete.

 Cannot find the class file for android.support.v4.app.Fragment. Fix the build path then try building this project  MainActivity        Unknown Java Problem

I figured this was because I did not yet complete all the steps and continued. When I add android-support-v4.jar via the method in the sample code, I get over 100 errors, all of which look like this (but with different line #s and paths):

R cannot be resolved to a variable  BasicMapActivity.java   /MainActivity/src/com/example/mapdemo   line 42 Java Problem

The only deviation from the tutorial that I took was my android-support-v4.jar was located in sdk\extras\android\support\v4

If there is anything you think I should try, or a bug that you know of, please tell me. Also if there is anymore helpful information I can give, just say so.

Edit: I looked more closely at the code, and there was no R.java in the gen folder. Might explain why nothing could find it.


回答1:


OK, first of all, know that Eclipse messes up with resources and R.java file many times.

Now,add the android.support.v4 as stated in the tutorials, you'll get your 100+ errors of R cannot be resolved. Now see if import android.R or import package_name.classname.R statement is present anywhere? Please delete these all

Now take a backup of the project somewhere, delete the project and make a new one. Now, copy the folders -- lib/libs, src, res, and Androidmanifest.xml from the backup to the new project folder (replace them). Now refresh the project in eclipse. It should work!




回答2:


Try three things

Right click on the map project and under android tools select add support library.

if still not resolved

Select project properties and check android private libraries and android support v4 under the order and export tab

if still not resolved

In the class which is giving error remove the import statement for the R.java file and press ctrl+shift+O then select and import the R file with project name



来源:https://stackoverflow.com/questions/16931788/trouble-importing-android-support-v4-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!