views:

187

answers:

1

Hi,

i have a strange (?) error in my android application. I have defined some arrays in values/arrays.xml the following way:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="perimeter">
        <item>10 miles</item>
        <item>20 miles</item>
        <item>30 miles</item>
    </array>

    <array name="regvalues">
        <item>1</item>
        <item>2</item>
        <item>3</item>
    </array>
</resources>

Now I want to use them in a ListPreference for a PreferenceActivity (defined by an xml file). So i set android:entries="@array/perimeter" android:entryValues="@array/regvalues" for this ListPreference. When I try to use this on my device the app crashes. (NullPointer in Dialog.close()) If I try to use the regvalues-items as Entries for the ListPreference i get a NullPointer in ArrayAdapter.createViewFromResource(int, View, ViewGroup, int) line: 355

So there seems to be sth wrong with the regvalues array. But what ?!? Eclipse shows me no errors at compile time. So everything in the xml-file and java-code is written correctly and there are no typos. Where is the problem?!?

+2  A: 

Use string-arrays instead of arrays. Even for ints.

alex