Android的[字符串数组]不能得到解决或不是场 [英] Android [string array] cannot be resolved or is not a field

查看:96
本文介绍了Android的[字符串数组]不能得到解决或不是场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到大约一个字符串数组错误(位于的strings.xml )不能够得到解决。

我所做的一切在网上说:


  1. 重启动Eclipse的

  2. 删除了文件夹中我的R.java文件

  3. 我的文件夹仍然是水库里面文件夹,不会移动

  4. 我的XML文件都没有误差修改

  5. 项目 - >清洁

  6. 我没有 android.R 进口在我的课。

  7. 选中的 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 你会得到你的ArrayList

I'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:

  1. Restarted Eclipse
  2. Deleted my R.java file inside the gen folder
  3. My values folder is still inside the res folder, not moved
  4. None of my XML files have erros
  5. Ran Project -> Clean
  6. I don't have android.R imported in my class.
  7. Checked the R.java class, it indeed doesn't have an app_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 use R.array you will get your arraylist.

这篇关于Android的[字符串数组]不能得到解决或不是场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆