Monday, May 16, 2011

Cleaning up the message log...

Well, I got into a little bit of a jam here. I'm trying to get rid of that annoying database not closed exception again.

So my test project wasn't compiling, and I deleted gen, and still no luck.

So I reverted, and now it doesn't compile, using this old AllWordsRow object which I thought I had changed before the commit - and I'm sure I committed it only this afternoon. What's going on?

So, I'm changing them back to question manually, just to get a compile.

I also took a manual backup before the revert, just in case. So, now I'm running the unit tests.

They all pass. Let's check the log.

Altogether, I'm getting 3 "android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here" messages.

Here's the first:

D/QuizStartActiity(14482): exit onCreate
I/ActivityManager( 101): Displayed com.jlptquiz.app/.JlptQuizStartActivity: +179ms
D/DataBaseHelper(14482): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> row is: level: 1, number: 1, kanji: 嗚呼, hiragana: ああ, english: Ah!, Oh!, Alas!
D/DataBaseHelper(14482): >>>>>>>>>>>>> closing database! <<<<<<<<<<<<<<<<
D/DataBaseHelper(14482): >>>>>>>>>>>>> closed database! <<<<<<<<<<<<<<<<
V/RenderScript_jni( 192): surfaceDestroyed
D/dalvikvm(14482): GC_EXPLICIT freed 165K, 54% free 3113K/6727K, external 1823K/2335K, paused 46ms
E/Database(14482): close() was never explicitly called on database '/data/data/com.jlptquiz.app/databases/jlpt'
E/Database(14482): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(14482): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1847)

I'd commented out all references to the database in the test, but they seemed to be running anyway. That's why I tried a clean - which caused the compile problem, whereupon I did the revert.

I did a search for those tests on the project - and found the tests in a copy that I had made! Delete that junk!

Ok, that's done, and I did an update to get it back to how it was originally.

However, It's *still* showing test runs which I had commented out in the tests:

free 2717K/5379K, external 1625K/2137K, paused 61ms
I/TestRunner(13653): started: testConstruct(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): finished: testConstruct(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): passed: testConstruct(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): started: testLookup(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): finished: testLookup(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): passed: testLookup(com.jlptquiz.app.test.TestInitUtils)
I/TestRunner(13653): started: testDatabaseNotEmpty(com.jlptquiz.app.test.TestJlptQuizStartActivity)
I/TestRunner(13653): finished: testDatabaseNotEmpty(com.jlptquiz.app.test.TestJlptQuizStartActivity)
I/TestRunner(13653): passed: testDatabaseNotEmpty(com.jlptquiz.app.test.TestJlptQuizStartActivity)

etc.


Maybe the class files didn't get deleted? I'm almost afraid to run another clean. Ok, I did. Now it compiles. Run it, and -

And they are still there - the same list of test. And, the db exceptions as well.

Let's make a copy of the test project and run that.

They're all still there. Try deleting the test creates most of them. Nope - they're still in the log.

Here's the stack trace:

/Database(13672): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(13672): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1847)
E/Database(13672): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
E/Database(13672): at com.jlptquiz.app.DataBaseHelper.openDataBase(DataBaseHelper.java:159)
E/Database(13672): at com.jlptquiz.app.Utils.createDB(Utils.java:314)
E/Database(13672): at com.jlptquiz.app.JlptQuizStartActivity.onCreate(JlptQuizStartActivity.java:44)

etc...

Note how createDB is still being called. Let's comment that out:

// this.myDbHelper = Utils.createDB(this);

Run and - same problem, of course.

Even though I'm clearing it, somehow the logcat seems too long...

I'll clear it, start a new tab and logcat from there...

Ah, no more non-existent tests. I somehow must have been looking at old logcats - but I know I was clearing it. Heck, it's even in the shell script to clear the screen and logcat. Somehow, I think I need to start a new tab every time I want to be sure I'm only seeing the new log.

Let's comment back in *one* database access.


@Override
protected void setUp() throws Exception {
super.setUp();

setActivityInitialTouchMode(false);

mActivity = getActivity();

this.myDbHelper = Utils.createDB(mActivity );

}

Perfect. No message. Now, one more.


public void testDatabaseOpens() {


try {
myDbHelper.openDataBase();
myDbHelper.close();

} catch (SQLException sqle) {

throw sqle;

}
Assert.assertEquals(true, true);

}

Great. Now, let's comment the rest back in.

Oops - null pointer exceptions. The problem is I have commented out the creation of the database in the activity, but am still getting it from the activity.


Comment out the offending line and rerun...


That's better. Let's do the next couple. Good. Now, the rest.

Good - all better. And that annoying message - gone. That message cannot be allowed - it's too ugly.

No comments:

Post a Comment