NetBeans 中的 Android 项目中缺少 R.java
我正在为 AP 计算机科学的一个项目做这个。
基础知识:
Mac OS X 10.5.8
NetBeans 7.0
Android SDK 3.0(级别 11)
因此,我正在 NetBeans 中尝试一些 Android API 演示(相对于 Eclipse,我更喜欢它),并且我使用样本\android-11\ApiDemos\ 作为源代码。 R.java 文件未生成并且“包 R 不存在”。我查看了其他答案,他们说清理并构建项目,但该选项在 NetBeans 中显示为灰色(因此只有“清理”和“构建”选项)。在切换到 Eclipse 之前我应该尝试什么?如果我需要更改操作系统,我还有一台运行 Windows 7 的计算机。谢谢!
I'm doing this for a project in AP Computer Science.
Basics:
Mac OS X 10.5.8
NetBeans 7.0
Android SDK 3.0 (Level 11)
So I'm trying out some of the Android API Demos in NetBeans (I prefer it over Eclipse) and I'm using samples\android-11\ApiDemos\ for the source. The R.java file is not generating and "package R does not exist". I've looked at other answers, and they say to Clean and Build the Project, but that option is grayed out in NetBeans (so are just the "Clean" and "Build" options). Any ideas on what I should try before I switch to Eclipse? I also have a computer running Windows 7 if I need to change the OS. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
右键单击您的项目并点击构建。它将为您生成缺少的 R 类。至少在 Netbeans 7.1 中对我来说是这样
Right-click your project and hit build. It will generate the missing R class for you. At least it did for me in Netbeans 7.1
只需右键单击该项目,选择“更新损坏的项目”命令,然后“构建”就不再是灰色的了。搭建起来,OK!!
右键菜单命令
Just right-click on the project, select the "Update broken project" command, then "Build" is not gray no longer. Build it, OK!!
The right-click menu command
我遇到了同样的问题,但我所做的只是“清理和构建”,然后由 Netbeans 创建 R 文件(运行 7.1)。
我必须在我的 Windows 7 电脑上以管理员身份运行 netbeans,然后它才能构建 R 文件。如果您要将项目保存到“安全”的位置,请确保 Netbeans 获得读取/写入/编辑该位置的所有必要权限
I had the same problem, but all I did was a "Clean and Build", and then the R file was created by Netbeans (running 7.1).
I had to run netbeans as administrator on my Windows 7 pc before it could build the R file. If you're saving the project to somewhere "secured", make sure that Netbeans gets all the neccessary rights to read/write/edit that location
获取 NetBeans 的 Android 插件,然后您将能够打开这些项目并使用它们。项目主页是 http://www.nbandroid.org/
可能需要一些初始步骤。在工具 | 设置 SDK 位置选项|杂项 |安卓。然后检查您的项目是否设置了一些构建目标(选择项目,右键单击并转到项目属性)。设置构建目标后,插件将(重新)生成构建脚本和所需的 .properties 文件。然后你就可以运行构建了。
-拉迪姆
Get Android plugin for NetBeans and then you will be able to open these project and play with them. The project home page is http://www.nbandroid.org/
Some initial steps may be needed. Set up SDK location in Tools | Options | Misc | Android. Then check that your project has some build target set in (select project, r-click and go to project properties). Once the build target is set plugin will (re-)generate build script and required .properties files. You'll be able to run build then.
-Radim
可能会发生一些事情,但大多数人会发生的是:
另外,这可能只是第一点,设置问题(明显损坏、错误的项目道具或类似的东西)使 R 无法生成,然后你就不会拥有 R 了。
但实际上,我我见过一些人们执行第 3 点的例子。
Several things could be going on, but what happens to most people is:
Also, it could just be point one, that a problem with the setup (manifest broken, wrong project props, or something like that) make R not generate, and then you won't have R.
But really, I've seen some examples of people doing point 3.
我遇到了同样的问题,这是由于 R 的包与 Main 的包不一样。我刚刚将 Main 移至与 R 相同的包,点击“构建”后一切正常。
I had the same problem and it was due to the package of R not being the same as the one for Main. I just moved Main to the same package as R and everything is fine after I hit Build.
就我而言,adb 丢失了。安装 adb 后,一切正常。
In my case adb was missing.After installing adb everything worked fine.
您只需右键单击该项目并从上下文菜单中选择构建。
(这对我有用。我正在使用 NetBeans 8.1)
You can just right-click the project and choose build from the context menu.
(This works for me. I am using NetBeans 8.1)