Error when copying to File.DirDefaultExternal

Discussion in 'Android Questions' started by CidTek, Jan 23, 2011.

  1. CidTek

    CidTek Active Member Licensed User

    I get an error when installing a file to SD storage executing this line. It worked since day one and now it just pops the error in the screenshot.

    File.Copy(File.DirAssets,"grt.db",File.DirDefaultExternal,"grt.db")
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    You can check LogCat (in the right pane) and see if there is any more information.
     
  3. CidTek

    CidTek Active Member Licensed User

    How do you select and copy text in the LogCat pane? All I can do is highlight one line at a time.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You will need to take a screenshot for now.
     
  5. CidTek

    CidTek Active Member Licensed User

    Perhaps this is the problem. I found this entry when I unchecked Filter.

    Data exceeds UNCOMPRESS_DATA_MAX (7897088 vs 1048576)

    Does the emulator has a size restriction per application because it is well below the 16 meg size of the emulator SD?
     
  6. agraham

    agraham Expert Licensed User

    Look at this link for the reason for the error Dealing with Asset Compression in Android Apps.

    "any compressed asset file with an uncompressed size of over 1 MB cannot be read from the APK."

    and a possible workaround

    "rename your file’s extension"
     
  7. CidTek

    CidTek Active Member Licensed User

    That got me past the original error, now I get a "No space left on device error".

    My SQLite file is 7712 KB.
     
  8. CidTek

    CidTek Active Member Licensed User

    OK, I restarted the emulator and wiped user data as an startup option.

    Running the app I now get a new error "Disk I/O Error" on this line...

    SQL1.Initialize(File.DirDefaultExternal, "grt.jet", False)

    Note that I renamed my db file with a .jet extension to prevent compression as suggested above.
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed User

    It might be an "emulator only" problem. It is worth checking it on a real device.
     
  10. CidTek

    CidTek Active Member Licensed User

    Problem solved.

    This applies only to SQLite databases created before uploading to the phone. Not to databases created on the phone.

    For some reason Android requires every database to have a table called android_metadata that includes at least one locale.

    Using your own SQLite database in Android applications | ReignDesign Blog

    However there is a better solution which Basic4Android doesn't support as far as I can see and that is to use the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when opening the database.
     
  11. nfordbscndrd

    nfordbscndrd Well-Known Member Licensed User

    That fix was also mentioned at in another thread, but the error I was getting was that the only table in my database was "not found". Strange that it was giving you different errors. I guess that the moral is that everyone putting an existing database on a device needs to make sure they have done the fix first.
     
  12. CidTek

    CidTek Active Member Licensed User

    I found that adding the android_metadata table is all I needed to do and didn't bother with the instructions to rename the primary key field in all the other tables.

    However there are plenty of mentions out there that passing SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when initializing the database eliminates that hassle. I just wish that B4A supported that.
     
    Last edited: Jan 26, 2011
  13. Erel

    Erel Administrator Staff Member Licensed User

    Will be fixed for the next update.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    The attached SQL library sets the NO_LOCALIZED_COLLATORS flag. Please try it and see if it fixes the problem.
     

    Attached Files:

    • Sql.zip
      File size:
      6.1 KB
      Views:
      52
  15. CidTek

    CidTek Active Member Licensed User

    Thanks Erel, I'll give it a test.
     
  16. CidTek

    CidTek Active Member Licensed User

    I removed the android_metadata table and tested the app and it works just fine.

    Thanks again Erel, I am developing this transit app in tandem with a friend who is doing the iPhone version and it makes using a common SQLite db so much easier.
     
  17. nfordbscndrd

    nfordbscndrd Well-Known Member Licensed User

    Where do the files go?
     
  18. CidTek

    CidTek Active Member Licensed User

    Program Files\Anywhere Software\Basic4Android\Libraries
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    You can also configure an "additional libraries path". It is set under Tools - Configure Paths.
     
  20. alfcen

    alfcen Well-Known Member Licensed User

    I have a database created with the SQLite Database Browser (CSV import).
    After deployment to the phone, I copied the database file back to the PC and found that a table called "android_metadata" containing a field "locale" = en_US has been created automatically.

    Apparently, not all phones or Android versions perform that step automatically, so I believe the modified library is neutral, thus safer (no such locale field added after switching to the new library).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice