java - Android internal Storage error -


i new android , writing simple game android.
in game, in games have score, now, want score saved in internal storage, , reason, manage save score, not load back.
here code:

final textview best = (textview) findviewbyid(r.id.best);  public int read = -1; public stringbuffer buffer = new stringbuffer(); public string scoretxt = buffer.substring(0, buffer.indexof(" ") + 1); public int score = 0; // save try {     fileoutputstream = openfileoutput("record.txt", context.mode_private);     fileoutputstream.write(scorestring.getbytes()); } catch (filenotfoundexception e) {     e.printstacktrace(); } catch (ioexception e) {     e.printstacktrace(); }finally {     if (fileoutputstream != null) {         try {             fileoutputstream.close();         } catch (ioexception e) {             e.printstacktrace();         }     } } toast.maketext(mainactivity.this, "save() works fine", toast.length_short).show();  // load try {     fileinputstream fileinputstream = openfileinput("record.txt");     while ((read = fileinputstream.read())!= -1){         buffer.append((char)read);     } } catch (filenotfoundexception e) {     e.printstacktrace(); } catch (ioexception e) {     e.printstacktrace(); } best.settext("best: " + scoretxt); toast.maketext(mainactivity.this, "load() " +    scoretxt, toast.length_short).show(); 


when run app, there no crash or special in logcat, when ever use scoretxt output nothing, " ".
can me solve problem? thanks

you never assign scoretxt value in code.


Comments