我正在尝试从三个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” 我该如何解决?
答案 0 :(得分:0)
SharedPreferences为null。尝试:
mColor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Editor editor = mColor.edit();
editor.putString(APP_PREFERENCES_COLOR, colorS);
editor.commit();
应该解决你的问题。
希望它有所帮助。