简体   繁体   English

布局xml崩溃应用中的Android @ + id

[英]Android @+id in layout xml crashing app

Firstly, I am new to android development. 首先,我是android开发的新手。 My app has been working fine with a number of different activities up until today. 直到今天,我的应用程序在许多其他活动中都运行良好。

I have been trying to add a new <Button /> element to one of my layout xml files. 我一直在尝试向我的布局xml文件中添加一个新的<Button />元素。 However, if I give it a new id (eg, android:id="@+id/button_unique" ) my app crashes on load, presumably as the resources are being loaded. 但是,如果我给它一个新的ID(例如android:id="@+id/button_unique" ),则我的应用程序在加载时崩溃,大概是因为正在加载资源。 If I change the id to an existing id (or remove android:id attribute completely) then the app loads fine. 如果我将ID更改为现有ID(或完全删除android:id属性),则应用会正常加载。

The new resource id does appear in R.java. 新的资源ID确实出现在R.java中。 However, I can see a No package identifier when getting value for resource number 0x7f060000 error in the logcat console. 但是,在logcat控制台中No package identifier when getting value for resource number 0x7f060000错误的No package identifier when getting value for resource number 0x7f060000 ,我看到一个No package identifier when getting value for resource number 0x7f060000 I'm not sure if this is related? 我不确定这是否相关吗?

Perhaps i'm making a silly mistake somewhere, but if anybody could help me get to the bottom of this it would be much appreciated. 也许我在某个地方犯了一个愚蠢的错误,但是如果有人可以帮助我深入浅出,将不胜感激。

Thanks 谢谢

I fixed this issue by rebuilding from scratch as the other post said. 我通过从头开始重新构建来解决此问题,如另一篇文章所述。 I entered ant clean before I built. 在建造之前,我进入了ant clean

It is really tough to know without you posting a code example, but one possible solution that could work is after naming the new unique button, is resave and rebuild the project before running it again in the emulator. 不发布代码示例就很难知道,但是可行的一种可行解决方案是在命名新的唯一按钮后重新保存并重建项目,然后在模拟器中再次运行它。 That will resave the new change in R.java which does not happen without the force of resave/rebuild. 这将重新保存R.java中的新更改,而没有重新保存/重建的力量是不会发生的。 Hope that helps. 希望能有所帮助。 Good Luck! 祝好运!

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

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