刚开始学android,照着书上例子做出现错误,不懂,代码贴出来高手指教下

爱_逆光 2012-12-03 08:25:10
建了个工程叫helloandroid。res里面的layout文件代码如下

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="161dp"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/activity_main_title"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_lable"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_game_lable"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/about_lable"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/exit_lable"/>

</LinearLayout>

调试后出现这样的错误:[2012-12-03 19:54:13 - helloandroid] G:\JAVA\myeclipse源文件\helloandroid\res\menu\activity_main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/menu_settings').
我大概能够看到好像是一个menu文件夹下的activity_main.xml文件不对劲。又不知道怎么搞,高手指点一下这是什么文件,怎么设置?这是我menu下的代码:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/menu_settings"/>

</menu>
...全文
311 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xupp 2012-12-10
  • 打赏
  • 举报
回复
引用 7 楼 love_love_yyou 的回复:
引用 6 楼 a65700170 的回复: 在工程目录下res-values的strings.xml文件下添加menu_settings的value值。谢谢大侠,不过我想知道为什么要在string.xml文件夹下添加menu,string.xml文件是干什么的?
比如说在xml中添加控件text的时候(android:text=""),就可以用string.xml文件(android:text="@string/menu_settings").如果直接写(android:text="菜单")也没错,但是旁边会有一个黄色感叹号。google推荐我们写在string.xml文件中。以便以后维护,优化逻辑思想。
爱_逆光 2012-12-05
  • 打赏
  • 举报
回复
引用 6 楼 a65700170 的回复:
在工程目录下res-values的strings.xml文件下添加menu_settings的value值。
谢谢大侠,不过我想知道为什么要在string.xml文件夹下添加menu,string.xml文件是干什么的?
明心如月 2012-12-04
  • 打赏
  • 举报
回复
引用 1 楼 wlcw16 的回复:
res/valus/strings 里面没有对menu_settings进行设置吧
应该是对的, android:title="@string/menu_settings" 改成androi:title="文字"也可以的
waltche 2012-12-04
  • 打赏
  • 举报
回复
你可以先将android:title="@string/menu_settings" 改成android:title=“随便写点什么”看是否不会报错如果不报错就是你的资源问题
xupp 2012-12-04
  • 打赏
  • 举报
回复
在工程目录下res-values的strings.xml文件下添加menu_settings的value值。
AMinfo 2012-12-04
  • 打赏
  • 举报
回复
贴strings.xml文件上来看看
ruancaipu 2012-12-03
  • 打赏
  • 举报
回复
引用 1 楼 wlcw16 的回复:
res/valus/strings 里面没有对menu_settings进行设置吧
瞎搞、、
wlcw16 2012-12-03
  • 打赏
  • 举报
回复
res/valus/strings 里面没有对menu_settings进行设置吧

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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