急!如何在java代码中获取string.xml中的字符串!

u010178674 2014-03-17 02:48:23
String str = Resources.getSystem().getText(com.derbysoft.hotel.R.string.hello).toString();

String str = Resources.getSystem().getString(R.string.hello);

上面2个都试过了,抛异常
NotFoundException
说找不到对应的ID,但是string.xml文件中明明有,R文件中也有ID

不知道什么原因,大家帮帮忙看下!
...全文
332 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
u010178674 2014-03-17
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
String str=getResources().getString(R.string.hello_world);
大神,能否加QQ,新手真心求教,不会经常麻烦您的,我都思考2个小时以上实在解决不了才发帖的!
u010178674 2014-03-17
  • 打赏
  • 举报
回复
引用 2 楼 u010178674 的回复:
[quote=引用 1 楼 hjywyj 的回复:] String str=getResources().getString(R.string.hello_world);
正解,大神啊,上回见过你,又一次解决了我的问题!非常感激! 为什么我上面的方法不行呢?[/quote] 我懂了,刚刚看文档发现了,getSystem()方法获得的是系统的资源,Resources对象就不是当前工程的对象了,难怪找不到ID
u010178674 2014-03-17
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
String str=getResources().getString(R.string.hello_world);
正解,大神啊,上回见过你,又一次解决了我的问题!非常感激! 为什么我上面的方法不行呢?
  • 打赏
  • 举报
回复
String str=getResources().getString(R.string.hello_world);

80,356

社区成员

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

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