简体   繁体   English

导入android-support-v4.jar时遇到问题

[英]Trouble Importing android-support-v4.jar

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 我正在尝试从https://developers.google.com/maps/documentation/android/intro页上制作示例代码教程。我很好地导入了google-play-services_lib,然后又导入了/ extras / google / google_play_services /示例/地图

At this point I have 2 errors: 此时,我有2个错误:

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): 当我通过示例代码中的方法添加android-support-v4.jar时,我遇到了100多个错误,所有错误看起来都是这样(但行号和路径不同):

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 与本教程的唯一差异是我的android-support-v4.jar位于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. 编辑:我仔细查看了代码,并且gen文件夹中没有R.java。 Might explain why nothing could find it. 可能会解释为什么什么都找不到。

OK, first of all, know that Eclipse messes up with resources and R.java file many times. 好的,首先,我们知道Eclipse多次弄乱了资源和R.java文件。

Now,add the android.support.v4 as stated in the tutorials, you'll get your 100+ errors of R cannot be resolved. 现在,按照教程中所述添加android.support.v4,您将获得100多个R无法解决的错误。 Now see if import android.R or import package_name.classname.R statement is present anywhere? 现在看看是否在任何地方都存在import android.Rimport package_name.classname.R语句? 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). 现在,将文件夹-lib / libs,src,res和Androidmanifest.xml从备份复制到新项目文件夹(替换它们)。 Now refresh the project in eclipse. 现在,在eclipse中刷新项目。 It should work! 它应该工作!

Try three things 尝试三件事

Right click on the map project and under android tools select add support library. 右键单击地图项目,然后在android工具下选择添加支持库。

if still not resolved 如果仍然无法解决

Select project properties and check android private libraries and android support v4 under the order and export tab 选择项目属性,然后在“命令和导出”选项卡下检查android私有库和android support v4

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 在给出错误的类中,删除R.java文件的import语句,然后按ctrl + shift + O,然后选择并导入具有项目名称的R文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM