When I check if the checkbox is checked, I get a Force Close in the following code:
public class preference extends PreferenceActivity implements OnSharedPreferenceChangeListener {
public static final String nwd = "nwd";
private CheckBoxPreference nwd_pref;
@Override
public void onCreate(Bundle savedInstanceState) {
...
nwd_pref = (CheckBoxPreference)getPreferenceScreen().findPreference(nwd);
...
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
...
if (nwd_pref.isChecked()){
// do code
}
...
}
}
I found this example during searching but looks the same to me.
Thanks for your help!
findPrefernece(..)
will "Return The Preference with the key, or null." It looks like "nwd" hasn't been set yet.