android中menu和R.java躲猫猫???

yangjun0709 2011-11-04 10:23:35
练习菜单资源时遇到如下问题:
TestMenuActivity.java文件,res/layout/test_menu.xml文件,res/menu/file_menu.xml文件代码应该没错。
但是Activity中到R.layout.test_menu,R.menu.file_menu, menu,case R.id.about,case R.id.exit均标有红线。难道找不到文件吗?明明有啊??
Project/clean后,R.java文件消失,再clean也不出来,但是当把res/menu文件删掉后,clean就出现R.java了,感觉挺奇怪到,不知道怎么回事?求牛哥牛姐们帮帮小弟!感激。。。
...全文
208 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangjun0709 2011-11-07
  • 打赏
  • 举报
回复
问题解决了,谢谢回复,
1.xml文件中有错误。。。
2.在导入android.R的时候出错了,建议删除import android.R 然后重新编译。
删除Android.R后,错误全部消失了。。。
小笨熊 2011-11-04
  • 打赏
  • 举报
回复
xml文件中有错误。。。
No resource found that matches the given name (at 'icon' with value '@drawable/help').就是类似这种错误
yangjun0709 2011-11-04
  • 打赏
  • 举报
回复
错误如下:
[2011-11-04 10:46:59 - Chapter03_Resource] W/ResourceType( 2140): Bad XML block: header size 62 or total size 0 is larger than data size 0
[2011-11-04 10:46:59 - Chapter03_Resource] F:\android-SDK\android-app\Chapter03_Resource\res\menu\file_menu.xml:3: error: No resource identifier found for attribute 'tile' in package 'android'
[2011-11-04 10:46:59 - Chapter03_Resource] F:\android-SDK\android-app\Chapter03_Resource\res\menu\file_menu.xml:3: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/file').
[2011-11-04 10:46:59 - Chapter03_Resource] F:\android-SDK\android-app\Chapter03_Resource\res\menu\file_menu.xml:27: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/edit').
[2011-11-04 10:46:59 - Chapter03_Resource] F:\android-SDK\android-app\Chapter03_Resource\res\menu\file_menu.xml:44: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/help').
yangjun0709 2011-11-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yangting_lisa 的回复:]
如果存在就不会出现红条。。。除非R中没有对应layout。
Project/clean后,R.java文件消失,再clean也不出来。。。。。。。。。此时你把我Build Automatical
ly选上。

把res/menu文件删掉后,clean就出现R.java了。。。。。这是因为eclispe会自动生成的
[/Quote]
Build Automatical之前就已经选上了,
Activity代码:
public class TestMenuActivity extends Activity{
private MenuInflater mi;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test_menu);
mi=new MenuInflater(this);
}
public boolean onCreateOptionsMenu(Menu menu){
mi.inflate(R.menu.file_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.about:
aboutAlert("本实例演示的是如何使用XML菜单资源来定义菜单 ");
break;
case R.id.exit:
exitAlert("真的要退出吗?");
break;
}
return true;
}
R.java:
public static final class layout {
public static final int main=0x7f030000;
public static final int test_bitmap=0x7f030001;
public static final int test_color=0x7f030002;
public static final int test_dimen=0x7f030003;
public static final int test_layout=0x7f030004;
public static final int test_menu=0x7f030005;
public static final int test_xml=0x7f030006;
}
里面倒是没有R.menu.file_menu
小笨熊 2011-11-04
  • 打赏
  • 举报
回复
如果存在就不会出现红条。。。除非R中没有对应layout。
Project/clean后,R.java文件消失,再clean也不出来。。。。。。。。。此时你把我Build Automatical
ly选上。

把res/menu文件删掉后,clean就出现R.java了。。。。。这是因为eclispe会自动生成的

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧