1

I am trying to build my first project using an existing sqlite database in Android Studio. All of the instructions I have referenced say to create an assets folder and copy the database into that folder. A call from the database helper will move the file for me for run time testing. The problem is that when the database is in the assets folder and I click on the plus sign next to the folder, Android studio immediately halts, closing all windows and displays no error. I am running studio 3.01 build #AI-171.4443003 dated 11/9/2017. I have applied all updates and the results are the same. I have tried using different extension for the DB with no luck.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I have since tried adding any other type of file to the assets folder and XML file work just fine. The database I am trying to add is 608KB, though I don't know why size would matter. – Steve Symonds Dec 17 '17 at 01:51

2 Answers2

1

Don't try opening the file from within Android Studio, I believe that it doesn't know how to handle SQLite files.

Rather let the App copy it to the it's final destination e.g. data/data/package/databases/ after which it can be opened.

SQLiteAssethelper can simplify the copy and open process. There are many tutorials for using SQLiteAssetHelper. Note! I believe you need to create a databases folder and place the database file into that directory.

Alternately, you can amend a standard databasehelper (subclass of SQLiteOpenHelper) e.g. this link has a rather long-winded example (simply ignore the Database Decryption i.e. join the two blocks of code). However, it does, split all the steps and does relatively comprehensive logging so can be useful for developing and understanding the process. It is also relatively flexible e.g. it caters for specifying a directory (or directories) (or not) within the assets folder and even multiple databases (up to 10 as is).

MikeT
  • 51,415
  • 16
  • 49
  • 68
  • Thanks for help. I probably was not as clear as I could have been. I have not tried to open the database in Studio. I place the DB in the assets folder and as soon as I expand the assets folder Studio aborts. No errors, nothing in the event log. I can place other files in the assets folder with no issue. I have tried with a new empty DB and get the same result. – Steve Symonds Dec 17 '17 at 22:47
  • try renaming the extension of the db file e.g. to `.qqq` or not even having a file extension. I suspect a file association has been setup (settings - editor - file types). [This may be of use](https://stackoverflow.com/questions/30969661/android-studio-file-type-extension-definitions) – MikeT Dec 17 '17 at 23:55
  • I tried both .qqq and no extension and I am still getting the same result. As soon as the assets folder expands, Studio aborts/closes with no errors. – Steve Symonds Dec 18 '17 at 21:51
  • Perhaps try uninstalling and then re-installing AS. – MikeT Dec 19 '17 at 00:38
  • I think that is likely where I am now. I did find the following error in the idea.log::android studio INFO - ide.actions.ShowFilePathAction - Exit code 1. Research showed that it could be related to the Kotlin plugin and that the plugin should be disabled. Did that with no effect. Studio dump and reload is next – Steve Symonds Dec 19 '17 at 01:38
  • Oh and copy the DB into the assets folder outside of AS e.g. using File Explorer for Windows. – MikeT Dec 19 '17 at 01:41
  • Yeah, I have tried that too. I have also reinstalled Studio with no change. – Steve Symonds Dec 20 '17 at 00:47
  • I have found another error log. java_error_in_studio_9808.log, it starts: A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000076026adf, pid=9808, tid=0x00000000000023ac # # JRE version: OpenJDK Runtime Environment (8.0_152-b01) (build 1.8.0_152-release-915-b01) # Java VM: OpenJDK 64-Bit Server VM (25.152-b01 mixed mode windows-amd64 compressed oops) # Problematic frame: # C [MSVCR100.dll+0x36adf] – Steve Symonds Dec 20 '17 at 01:11
  • Problem solved. I was caused by God Mode on the desktop, very obtuse the solution was found here:https://stackoverflow.com/questions/43819549/fatal-error-crashing-on-latest-version-of-java-on-windows-10-machine – Steve Symonds Dec 20 '17 at 01:17
  • I sort of understand now, would never have found that myself though. Great that you've got things working. – MikeT Dec 20 '17 at 01:34
1

Problem solved. I was caused by God Mode on the desktop, very obtuse the solution was found here:Fatal error crashing on latest version of Java on Windows 10 machine.

From the file path error I identified in Studio, I was able to search back and found a reference to outdated java installation. I then made sure that Java was up to date. When the problem persisted, I then went on a search for logs again and found a java error log in the Users\ folder. From that error I continued to search until I found the stackoverflow link, which ultimately solved the issue.

  • 1
    Rather than just posting a link, answer a) determined what the problem was that led you to the link and how you then fixed it giving credit to the link. Thus the answer gets linked to tags android/sqlite and assets so if some happens to get the same issue they may then find this answer. Definitely an upvote from me if you do so. – MikeT Dec 20 '17 at 01:40