书写背景色

Roki20121

我正在尝试写从三个SeekBars获得的背景色。我使用此代码:

SharedPreferences mColor;
public static final String APP_PREFERENCES_COLOR="color";
    colorS = rgbToHEX(r, g, b);
    try {

                Editor editor = mColor.edit();
                editor.putString(APP_PREFERENCES_COLOR, colorS);
                editor.apply();
                } catch(Exception e){
                 Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
                }
    }

但是我看到消息“ java.lang.NullPointerExeption”,该如何解决?

少年Buckeridge

获取编辑器时,SharedPreferences为null。尝试:

mColor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Editor editor = mColor.edit();
editor.putString(APP_PREFERENCES_COLOR, colorS);
editor.commit();

应该可以解决您的问题。

希望能帮助到你。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章