public void onClick(View v) {
    switch(v.getId()){
    case R.id.save2:
        s = text.getText().toString();
        number = Float.parseFloat(num.getText().toString());
        SharedPreferences.Editor editor = shared.edit();
        editor.putString("sharedtext",s);
        editor.putFloat("sharednum",number);
        editor.commit();
        Toast.makeText(this,"save2",Toast.LENGTH_SHORT).show();
        break;
    case R.id.load2:
        String returner = shared.getString("sharedtext","Returner fail");
        float returnnum = shared.getFloat("sharednum",0);
        text.setText(returner);
        num.setText(returnnum); //error here
        Toast.makeText(this,"load2",Toast.LENGTH_SHORT).show();
        break;
    case R.id.page2:
        intent= new Intent(this,SharedPreferencesActivity.class);
        startActivity(intent);
        Toast.makeText(this,"page2",Toast.LENGTH_SHORT).show();
        break;
    }
how could i resolve this error?
how to make something like setInt(int num);
btw the variable num and text are both EditText
If you pass a numeric value as the text to a text field, Android will try to interpret it as a resource Id. Make it a text first. The preferred way is to do:
num.setText(String.valueOf(returnnum));
(For good practices on conversion to string, check this post)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With