Android的[字符串数组]不能得到解决或不是场 [英] Android [string array] cannot be resolved or is not a field
本文介绍了Android的[字符串数组]不能得到解决或不是场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到大约一个字符串数组错误(位于的strings.xml
)不能够得到解决。
我所做的一切在网上说:
- 重启动Eclipse的
- 删除了
根
文件夹中我的R.java文件 - 我的
值
文件夹仍然是水库里面
文件夹,不会移动 - 我的XML文件都没有误差修改
- 然
项目 - >清洁
- 我没有
android.R
进口在我的课。 - 选中的
R.java
类,它确实不具有app_categories
属性(我的数组的名字)
在XML的相关部分:
<字符串数组名=app_categories>
<项目>猫1 LT; /项目>
<项目>猫2'; /项目>
<项目>猫3'; /项目>
<项目>猫4℃; /项目>
<项目>猫5℃/项目>
<项目>猫6≤/项目>
<项目>猫7 LT; /项目>
<项目>猫8示/项目>
<项目>猫9 LT; /项目>
< /字符串数组>
在Java code:
的String [] = CATEGORYNAMES getResources()getStringArray(R.string.app_categories)。
我的所有其他字符串都可见。我定义就是这样的另一个数组,一个要么是不可见的。
下面的确切错误:
app_categories不能得到解决或不是场[CLASS_NAME]的.java [路径] 45行Java问题
解决方案
刚刚尝试了这种方式:
getResources()的getString(R.array.app_categories_list)。
块引用>而不是
R.string
的使用R.array
你会得到你的ArrayListI'm getting an error about a string array (located in
strings.xml
) not being able to be resolved.I've done everything the internet says:
- Restarted Eclipse
- Deleted my R.java file inside the
gen
folder- My
values
folder is still inside theres
folder, not moved- None of my XML files have erros
- Ran
Project -> Clean
- I don't have
android.R
imported in my class.- Checked the
R.java
class, it indeed doesn't have anapp_categories
property (my array's name)The relevant part of the XML:
<string-array name="app_categories"> <item >Cat 1</item> <item >Cat 2</item> <item >Cat 3</item> <item >Cat 4</item> <item >Cat 5</item> <item >Cat 6</item> <item >Cat 7</item> <item >Cat 8</item> <item >Cat 9</item> </string-array>
The Java code:
String[] categoryNames = getResources().getStringArray(R.string.app_categories);
All my other strings are visible. I have another array defined just like this one, and that one isn't visible either.
Exact error below:
app_categories cannot be resolved or is not a field [class_name].java [path] line 45 Java Problem
解决方案Just try out this way :
getResources().getString(R.array.app_categories_list);
Instead of
R.string
useR.array
you will get your arraylist.这篇关于Android的[字符串数组]不能得到解决或不是场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文