Reputation: 6602
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:
gen
foldervalues
folder is still inside the res
folder, not movedProject -> Clean
android.R
imported in my class.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
Upvotes: 2
Views: 6066
Reputation: 9
a solution may be to create the R manually:
just hover over the error in the activity file where the problem was and then manually create it, which will cause R to generate the string array you created in strings.xml
Upvotes: 0
Reputation: 1682
Don't put your string arrays in strings.xml You must create a new file called arrays.xml and place them there. And when calling you need R.arrays.myarray, not R.strings.MyArray
Upvotes: 4
Reputation: 2547
After cleaning your project try restarting the adb server by running adb kill-server and adb start-server from the command line
Upvotes: 0
Reputation: 23638
Just try out this way :
getResources().getString(R.array.app_categories_list);
Instead of R.string
use R.array
you will get your arraylist.
Upvotes: 9