Android Studio无法为SharedPreferences Samsung Galaxy s8创建目录

时间:2018-02-08 20:11:59

标签: java android

所以,当它试图在Samsung Galaxy s8上创建SharedPreferences时,它会给我这个错误而且它不起作用 无法为SharedPreferences文件创建目录/data/user/0/com.samsung.android.service.peoplestripe/shared_prefs/setting.xml

这是代码

    private EditText milkdone;
private EditText brixdone;
private double milkdone2;
private double brixdone2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    milkdone = (EditText) findViewById(R.id.milkliter);
    brixdone = (EditText) findViewById(R.id.brix);

    milkdone.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                milkdone2 = Double.parseDouble(milkdone.getText().toString());
                brixdone2 = Double.parseDouble(brixdone.getText().toString());
                LoadPreferences();
                double test2 = brixdone2 + milkdone2;
                TextView change = (TextView) findViewById(R.id.textView3);
                change.setText(String.valueOf(test2));
                handled = true;
            }
            return handled;
        }

    });
    brixdone.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE){
                milkdone2 = Double.parseDouble(milkdone.getText().toString());
                brixdone2 = Double.parseDouble(brixdone.getText().toString());
                LoadPreferences();
                double test2 = brixdone2 + milkdone2;
                TextView change = (TextView) findViewById(R.id.textView3);
                change.setText(String.valueOf(test2));
                handled = true;
            }
            return handled;
        }
    });
    };
    public void onStop() {
        super.onStop();
        SavePreferences("savedbrixdone",String.valueOf(brixdone2));
        SavePreferences("savedmilkdone",String.valueOf(milkdone2));

    }
private void SavePreferences(String key, String value){
    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);
    editor.commit();
}

private void LoadPreferences(){
    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
    String brixdone2 = sharedPreferences.getString("savedbrixdone", "");
    String milkdone2 = sharedPreferences.getString("savedmilkdone", "");

}

0 个答案:

没有答案