Android not installing database

You must Login before you can answer or comment on any questions.

I can not get a database to install for android. As soon as the app launches it comes up with "Cannot call method "execute" on null." I've renamed the database with an extension of mp3. I've also tried using ddms to put in the database onto the emulator as prescribed <a href="http://developer.appcelerator.com/question/61591/problem-with-sqllite-db-on-android">here: http://developer.appcelerator.com/question/61591/problem-with-sqllite-db-on-android </a> but where exactly would I put it? I've put it in a number of spots and still no luck.

1 Answer

You cannot use the .execute method until you have either done an .open() or .install() on the database (and they worked). So it would help if you showed us the code that is failing. In general, if you are trying to include a prebuilt SQLite database with your program you can do this:

  1. Add the file to your project Resources folder prior to compilation
  2. If the file is over 5MB, change the extension to *.mp3
  3. In the app.js file, do this
    var db = Ti.Database.install('myDb.mp3','myDb');
    if ( db ) {
        db.execute('Select * from myTable');
    } else {
        alert('Database install failed');
    }
— answered 2 years ago by Doug Handy
answer permalink
3 Comments
  • Thanks, Doug, for the response but I did all that before I asked the question. Anyway, I created a new project, copied over my resources folder, built again, and like magic it worked. Not sure why. Just a titanium gremlin.

    var myProblem = Ti.Gremlin;

    — commented 2 years ago by Kevin Ripka

  • Kevin, next time you get a random database problem, I always uninstall the application from the phone I'm testing it on and the touch the tiapp.xml file in the project folder. I think the latter is the thing that fixes the problem, see:
    http://developer.appcelerator.com/question/90491/creating-db-on-android-throws-cannot-call-method-open-of-undefined

    Doug, Thanks for your help with the problem I had here:
    http://developer.appcelerator.com/question/96771/location-of-titanium-sql-database-on-android
    I clicked 'best answer' without realising it would close the question and I couldn't thank you. So, thank you...!

    — commented 2 years ago by James Phillips

  • @Doug - Big thanks for the tip on renaming the database to MP3. We where having issues with a database of 12mb (~50k rows) not being installed. No issues after renaming. Thanks again for the tip!!

    — commented 2 years ago by Dan Boorn

Your Answer

Think you can help? Login to answer this question!