I try to implement MultiSelectListPreference for my settings view:
<MultiSelectListPreference
android:title="@string/title"
android:summary="@string/message"
android:key="pref_foobar"
android:defaultValue="@array/empty_array"
android:entries="@array/fooArray"
android:entryValues="@array/fooValues" />
The array:
<resources>
<string-array name="fooArray">
<item>Foo</item>
<item>Bar</item>
</string-array>
<string-array name="fooValues">
<item>foo_value</item>
<item>bar_value</item>
</string-array>
<string-array name="empty_array"/>
</resources>
However this gives me following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproject/.SettingsActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Set
Full stacktrace: http://pastebin.com/kBDByXY5
Any ideas whats wrong?
Code:
public class SettingsActivity extends Activity {
private static final String TAG_SETTINGS_FRAGMENT = "SETTINGS_FRAGMENT";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new PreferenceFragment(), TAG_SETTINGS_FRAGMENT).commit();
}
}
public static class PreferenceFragment extends android.preference.PreferenceFragment{
public PreferenceFragment() {
//required
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
It feels like you already have a plain String
preference under this key on your device or emulator. Try completely uninstalling and reinstalling the app, or using "Clear Data" for the app in its screen in Settings, to wipe out your existing SharedPreferences
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With