Question

I've just finished Notepadv# tutorials. And then, I connect through console(adb shell) the 'data' file Notepadv3 tutorial. I tried something.

  1. Delete notes table, and re-run.
    • Do not work.
  2. Delete data file(db file), and re-run.
    • Work.

If you worked Notepadv# tutorials, you may know about some pre-processing in NotesDbAdapter class. At that code position, I found "selecting db" on constructor, "creating table" on onCreate method and "update table" on onUpgrade method.

By that method, database(file named data) create table when onCreate called after constructor. No way, that didn't work. Above 2 like-moron test caused by that nonsense. Does anyone drop the notes table on console? I can't find why create doesn't work.

ps - So sorry about stupid English.

Was it helpful?

Solution

Your database onCreate method will only create the database if it does not exist. If it is corrupt (i.e. you've dropped the Notes table), or exists but is empty, then it is up to the application to detect that and recover.

This is why the notepad example fails when you drop the table (the database exists, so onCreate is not called and your database is corrupt), but when you delete the database it does work because onCreate is called and it recreates the database.

So basically, don't do that :-)

See the SQLiteOpenHelper documentation for a more detailed description.

OTHER TIPS

Tried to uninstall the application or deleting the application data from Settings->manage application?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top