0

Hi everybody and sorry if i did not find the answer myself yet - i think i fooled myself but cannot find where. Idea is to adapt an example i found here for a shared preferences class:

public class spHelper {

    private final Context context;
    private final SharedPreferences sharedPrefs;
    private String strTest;

    public spHelper(Context context) {
        this.context = context;
        sharedPrefs = context.getSharedPreferences("demo", Context.MODE_PRIVATE);
    }

    public String getStrTest() {
        strTest = sharedPrefs.getString("keyTest","yet empty");
        return strTest;
    }
}

Then i tried to use it, but i get the error above in the last line of code - why? Maybe i should have a break.. i feel its something quite stupid.. but i don't see it - please open my eyes..

public class MainActivity extends AppCompatActivity {

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


        TextView t = (TextView) findViewById(R.id.txtInfo);
        spHelper sph = new spHelper(this);
        t.setText(spHelper.getStrTest());

    }
}
Andy Turner
  • 137,514
  • 11
  • 162
  • 243
loeten
  • 1
  • 3

0 Answers0