做Android教程时没有生成R.java? [英] R.java not generating while doing Android tutorial?
问题描述
所以我正在编写 android.com 提供的 Android 教程.但是,当我进入添加操作按钮部分时,我尝试使用支持带有支持库的 Android 2.1 的代码,这似乎导致 .xml 文件中的错误.我有相同的 .xml 名称,main_activity_actions.xml",代码完全相同.然而,我注意到我的 R.java 能够在我取出时生成
So I'm working on the Android tutorial provided by android.com. However, when I get to the Adding Action Buttons portion, I try to use the code that supports Android 2.1 with support libraries and that seems to cause an error in the .xml file. I have the same .xml name, "main_activity_actions.xml" with the same exact code. I notcied that my R.java however, was able to generate whenever I took out
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="ifRoom" />
所以,我不太确定这有什么问题.我的代码在整个教程中几乎是一样的.
So, I'm not really sure what's wrong with this. My code is virtually the same throughout the tutorial up through this point.
教程链接:http://developer.android.com/training/basics/actionbar/adding-buttons.html
完整代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
app:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
推荐答案
支持库是否添加到项目中?右键单击项目,Android 工具 --> 添加支持库.
Are the support libraries added to the project? Right-click the project, Android Tools --> Add Support Libraries.
如果这不是问题,您需要发布更多信息.发布构建错误,其中应该有与无法生成 R 文件的原因相关的信息.
If that isn't the issue, you need to post more information. Post the build errors, there should be information in there related to why the R file could not be generated.
这篇关于做Android教程时没有生成R.java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!