Tuesday, August 9, 2011

Sqllite table not found exception part 2

Well, the old Sqlite table not found exception is rearing its ugly head again. As it turns out, the previous fix I mentioned a couple of posts ago didn't do the trick.

Here's another look at the exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kanjisoft.jlpt5.free/com.jlptquiz.app.StartActivity}: android.database.sqlite.SQLiteException: no such table: word_review_schedule: , while compiling: insert into word_review_schedule(_id, last_review_date,next_review_date) values (?, ?, ?)

What I failed to notice or really understand earlier was the key phrase "while compiling". So, the problem wasn't on the insert statement - it was on the compilation of this SQLiteStatement.

private static final String INSERT = "insert into " + WORD_REVIEW_SCHEDULE
+ "(_id, last_review_date,next_review_date) values (?, ?, ?)";

This takes place right after the open database command:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,

SQLiteDatabase.OPEN_READWRITE);

this.insertStmt = this.myDataBase.compileStatement(INSERT);


I'm thinking that it's just too soon after the database is opened, and the compile statement actually needs the db to be fully available. So, my proposed solution to do a lazy initialize, like so:

public long insert(int id, String lastReviewDate, String nextReviewDate) {


if (null == this.insertStmt) {
this.insertStmt = this.myDataBase.compileStatement(INSERT); // Lazy init.
}
this.insertStmt.bindLong(1, id);
this.insertStmt.bindString(2, lastReviewDate);
this.insertStmt.bindString(3, nextReviewDate);

return this.insertStmt.executeInsert();

}
}


This won't happen until the user has actually seen a question and pressed a control to answer, long after the open has completed.

Ok, so, I'm going to use the scripts I set up as described in the last post to get this update onto the market.

First. run the build_all. I'm very pleased with myself that I did this. It's better than the arduous process of exporting each unsigned apk individually.

Ok, it's already done. Now, I actually haven't written the script yet to generate the signed jars for all the project, but it's a matter of making a file with these statements:

./gen_signed_jar JlptQuiz5Full
./gen_signed_jar JlptQuiz4Full
./gen_signed_jar JlptQuiz3Full
./gen_signed_jar JlptQuiz2Full
./gen_signed_jar JlptQuiz1Full
./gen_signed_jar JlptQuiz5Free
./gen_signed_jar JlptQuiz4Free
./gen_signed_jar JlptQuiz3Free
./gen_signed_jar JlptQuiz2Free
./gen_signed_jar JlptQuiz1Free

Let's run it.

Perfect! 10 projects, 10 passwords, only a second or two between entries. Usability far superior to using the long-lasting ant compile builds to sign.

Ok. The time has come. I now need to upload these guys. That's something I can't script away.

Actually, I can't be sure the previous fix didn't work, because it turns out that when you activate an APK, you also have to hit the save tab. Lesson learned.

We're done for now.







No comments:

Post a Comment