Hello, I'm trying to create a PreferenceScreen with a CheckBoxPreference which depends on an other CheckBoxPreference using the setDependency() method, as shown in the code below.
While calling the setDependency() method, I get the following Exception: java.lang.IllegalStateException: Dependency "preferenceKey1" not found for preference "preferenceKey2" (title: "chbPref2" at android.preference.Preference.registerDependency (Preference.java:1007) at android.preference.Preference.setDependency(Preference.java: 1124) at test.preferences.TestPreferencesActivity.createPreferenceScreen (TestPreferencesActivity.java:28) at test.preferences.TestPreferencesActivity.onCreate (TestPreferencesActivity.java:13) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1123) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2231) ... 11 more I have no idea what's wrong with this code. Without the setDependency () call, the PreferenceScreen works well. package test.preferences; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; public class TestPreferencesActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setPreferenceScreen(this.createPreferenceScreen()); } private PreferenceScreen createPreferenceScreen() { PreferenceManager preferenceManager = this.getPreferenceManager (); PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(this); CheckBoxPreference chbPref1 = new CheckBoxPreference(this); chbPref1.setTitle("chbPref1"); chbPref1.setKey("preferenceKey1"); preferenceScreen.addPreference(chbPref1); CheckBoxPreference chbPref2 = new CheckBoxPreference(this); chbPref2.setTitle("chbPref2"); chbPref2.setKey("preferenceKey2"); chbPref2.setDependency(chbPref1.getKey()); preferenceScreen.addPreference(chbPref2); return preferenceScreen; } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---