Question

I have a problem with these SharedPreferences:

private String StringaCirc;
private StringBuffer StringAux;

[...]

public void stringaCirc(){
    for(int i=0;i<1000;i++)
        StringaCirc1.setCharAt(i, '0');
    StringaCirc=StringaCirc1.toString();
    SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("StringaCirc", StringaCirc);
    editor.commit();
    }

But when i call the function the app crashes...What is the problem?

Was it helpful?

Solution

It seems that you haven't defined StringaCirc1 in your method.

try to add this before for() loop

String StringaCirc1 = "";

you also should use lowercase first letters for your strings for readability

private String stringaCirc;
private StringBuffer stringAux;

[...]

public void stringaCirc() {
    String stringaCirc1 = "";
    for(int i=0;i<1000;i++)
        stringaCirc1.setCharAt(i, '0');
    stringaCirc = stringaCirc1.toString();
    SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("StringaCirc", stringaCirc);
    editor.commit();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top