Android Rendering Problems Couldn't resolve re

2019-03-27 15:05发布

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:

<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...

My strings.xml file looks like this:

<string name="btnText">GO!</string>

I get this error message: Rendering Problems Couldn't resolve resource @string/app_name (2 similar errors not shown)

The problem is that the button text says @string/btnText instead of GO!

3条回答
不美不萌又怎样
2楼-- · 2019-03-27 16:01

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...

查看更多
疯言疯语
3楼-- · 2019-03-27 16:02

[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.]

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.

In many cases, simply refreshing the layout preview will solve this problem (of course I'm assuming that you do have the string app_name defined). The arrow marks the refresh button (so many buttons!).

enter image description here

查看更多
欢心
4楼-- · 2019-03-27 16:08

I had the same issue, I tried closing android studio and open it again and it works!

查看更多
登录 后发表回答