Pergunta

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?

Foi útil?

Solução

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();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top