开发者

CheckBoxPreference isChecked causes a FC in a preferenceActivity

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
    publi开发者_如何学编程c 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜