F
F
FreedomOfChoice2019-01-05 10:23:34
Android
FreedomOfChoice, 2019-01-05 10:23:34

Error on startup. What is wrong in the code?

public class Settings extends AppCompatActivity {

    SharedPreferences sf;
    EditText money;
    public static final String preference = "pref";
    public static final String saveIt = "saveKey";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        money = (EditText) findViewById(R.id.text_input_money);
        sf = getSharedPreferences(preference, Context.MODE_PRIVATE);

    }

    public void save(View view) {

        String store = money.getText().toString();
        SharedPreferences.Editor editor = sf.edit();
        editor.putString(saveIt, store);
        editor.commit();


    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nikto_b, 2019-01-05
@nikto_b

Wangyu, calling save before creating an activity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question