在 strings.xml 文件中,我有以下内容:
<resources>
<string name="itemTag">1</string>
<string name="item2Tag">2</string>
</resources>
但是当我进入一项 Activity 并尝试通过此访问时:
ib.setTag(R.string.itemTag, "itemTag");
它在 itemTag 上出现错误:
itemTag cannot be resolved or is not a field
这是什么意思以及如何解决?
编辑:代码:
public void changePicture(ImageButton ib) {
ib.setTag(R.string.itemTag, "itemTag");
getResources().getString(R.string.itemTag);
}
最佳答案
检查您的 java import
,您可能导入了与当前包中不同的 R.java
。
删除所有导入,然后使用 Eclipse Ctrl+Shift+O(组织导入)并选择要导入的正确包。
关于java - 如何解决 "itemTag cannot be resolved or is not a field"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976498/