Java Android 渲染问题无法解析资源@string/app_name
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24485012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Rendering Problems Couldn't resolve resource @string/app_name
提问by CoderOgden
I'm new to android programming and I don't understand what I'm doing wrong. I try to make a button like this in the xml file:
我是 android 编程的新手,我不明白我做错了什么。我尝试在 xml 文件中制作一个这样的按钮:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnText"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
This works fine, without the android:text="@string/btnText" part...
这工作正常,没有 android:text="@string/btnText" 部分......
My strings.xml file looks like this:
我的 strings.xml 文件如下所示:
<string name="btnText">GO!</string>
I get this error message: Rendering Problems Couldn't resolve resource @string/app_name (2 similar errors not shown)
我收到此错误消息:渲染问题无法解析资源 @string/app_name(未显示 2 个类似错误)
The problem is that the button text says @string/btnText instead of GO!
问题是按钮文本显示 @string/btnText 而不是 GO!
回答by Evan Martinez
I had the same problem with all 5 buttons in my main activity - searched all over the place for what might be wrong, didn't find anything - so I decided to run it on a physical device - all buttons displayed as wanted (didn't give them any function at this stage though) and when I got back to the layout window, the error just wasn't there anymore - you might give that a try...
我的主要活动中的所有 5 个按钮都遇到了同样的问题 - 到处搜索可能有什么问题,没有找到任何东西 - 所以我决定在物理设备上运行它 - 所有按钮都显示为想要的(没有'不过在这个阶段不要给他们任何功能),当我回到布局窗口时,错误不再存在 - 你可以尝试一下......
回答by Scott Biggs
[Note that this answer was written in 2016 for Android Studio 2.0! Android Studio has changed significantly since then. This answer helped a lot of people at the time, but may no longer be relevant.]
[请注意,此答案是在 2016 年为 Android Studio 2.0 编写的!从那时起,Android Studio 发生了重大变化。这个答案当时帮助了很多人,但可能不再相关。]
It's possible that the layout preview started drawing before all the files were processed. Android Studio and Eclipse both frequently suffer from tool synchronization problems.
布局预览可能在处理所有文件之前就开始绘制。Android Studio 和 Eclipse 都经常遇到工具同步问题。
In many cases, simply refreshing the layout preview will solve this problem (of course I'm assuming that you dohave the string app_name defined). The arrow marks the refresh button (so many buttons!).
在许多情况下,只需刷新布局预览即可解决此问题(当然,我假设您确实定义了字符串 app_name)。箭头标记刷新按钮(按钮太多了!)。
回答by Oussama
I had the same issue, I tried closing android studio and open it again and it works!
我遇到了同样的问题,我尝试关闭 android studio 并再次打开它,它可以工作!