2

The problems is that I am out of disk space on the internal memory so the write fails. I am having trouble handling it confidently as the exception gets dropped on the floor ( see http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/android/app/ContextImpl.java#3169 ). The .commit() call will return false and I can use that to handle the write error but I dont know if the fail is from space issue or from something else.

How do I know what the commit failed with?

stack trace

06-29 20:01:17.507: WARN/ApplicationContext(19221): writeToFile: Got exception:
        java.io.IOException: No space left on device
        at org.apache.harmony.luni.platform.OSFileSystem.write(Native Method)
        at dalvik.system.BlockGuard$WrappedFileSystem.write(BlockGuard.java:171)
        at java.io.FileOutputStream.write(FileOutputStream.java:300)
        at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
        at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
        at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
        at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:185)
        at android.app.ContextImpl$SharedPreferencesImpl.writeToFile(ContextImpl.java:3191)
        at android.app.ContextImpl$SharedPreferencesImpl.access$800(ContextImpl.java:2756)
        at android.app.ContextImpl$SharedPreferencesImpl$1.run(ContextImpl.java:3106)
        at android.app.ContextImpl$SharedPreferencesImpl.enqueueDiskWrite(ContextImpl.java:3127)
        at android.app.ContextImpl$SharedPreferencesImpl.access$100(ContextImpl.java:2756)
        at android.app.ContextImpl$SharedPreferencesImpl$EditorImpl.commit(ContextImpl.java:3049)
browep
  • 5,057
  • 5
  • 29
  • 37

2 Answers2

0

How about just checking the available free space before you write the file and calculating if there is enough space to fit your file? You can see how to check memory here Check Internal and External memory

Community
  • 1
  • 1
mbwasi
  • 3,612
  • 3
  • 30
  • 36
-1

Can you post your code? Also is this a real device on an emulator? SharedPerferences are literally just an xml file. You can browse them yourself by usingadb shell and going to the data/data/your.package.name/sharedpreferences

Have you tried freeing up memory on your device? Deleting some old files or upping the VM size. Also, it was just noted in #IO2012 to use apply() instead of commit(). Unless you really want your return value, which most people don't.

Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
  • I am not trying to free up space. I want to know why the commit failed, not fix it. The device doesnt matter as any device can run out of space. Did you read the part about getting the return value to see if it failed? – browep Jun 29 '12 at 21:37
  • 1
    The commit failed because you are out of space man java.io.IOException: No space left on device So you should try to free some up. The device does matter if your not able to write to it. – Frank Sposaro Jul 01 '12 at 22:17
  • the commit method returns false, does not throw an exception. The exception above is from the logs. Read the source link I posted. The method swallows the exception and returns false. – browep Jul 02 '12 at 19:09
  • Alright man. I don't want to spend anymore time trying to help you since clearly I'm being downvoted for offering suggestions. – Frank Sposaro Jul 02 '12 at 19:15