Search code examples
androidxmlgetresource

getIntArray returns 0 from my XML file


Working on an SQLite database. I'm importing data from my XML file. The problem I got is when I try to read my int array, I only get 0 as values.

Part of my XML file :

<integer-array name="difficulties">
    <item>8</item>
    <item>12</item>
    <item>4</item>
    <item>5</item>
    <item>7</item>
</integer-array>

How I am getting the array :

public int[] getDifficulties() {
    Resources res = this.getResources();
    return res.getIntArray(R.array.words);
}

How I am testing the array :

int[] test = getDifficulties();
for(int i=0; i<test.length; i++) {
    Log.i("MESSAGE", Integer.toString(test[i]));
}

Thanks for help!


Solution

  • You are not accessing your difficulties array correctly. Replace return res.getIntArray(R.array.words); with return res.getIntArray(R.array.difficulties);