+2  A: 

I haven't had a chance to test out my theory yet, but it looks like "DATABASE_CREATE" defines "id", and you're retrieving "_id" in your queries. You define "KEY_ROWID" up top, but don't use that constant in your DB creation query.

However, if this was your main problem, I dont't know why "If i try to do a query directly in to the DatabaseHelper create() metod it goes, but out of this function it doesn't".

Hope that helps.

Adam
I corrected the KEY_ROWID define but the prolem persist.NB: In to the onCreate() metod of the DatabaseHelper there are to delete(...), i put them to try this querys from there and they don't crash, but outside yes!
Skatephone
Agree, I see some inconsistencies using the id column as well (you use "id" to create the column but are using "_id" to fetch and KEY_ROWID to get the value in your fetchAllGirls() this would obviously fail cuz _id is not in your cursor). I suggest you use the constant 'BaseColumns._ID' for all PK id columns. Add PK constraint to this column in your create statements and DO NOT add it to ContentValues on create, let SQLite autogenerate for you.
Ricardo Villamil
I resolved changing the name of the database, maybe was because of some precedent table. Bye bye
Skatephone
A: 

In general, there's not much error handling going on. There are a number of places I can see the code might crash.

For starters, surround these things with try-catch

  • parseInt()
  • Performing queries, inserts, updates,

Also:

  • Make sure your mDB variable isn't null before calling its close() method.
  • getcolumnIndex - instad of using this, query your records in the order you want, then you will know what index each field is in. for example: SELECT id,name from table then you can access name with getString(1);

And most importantly of all, familiarize yourself with the adb logcat (link below). This tool will extract the log buffer from your device AND monitor it in real time, for crashes.

If your app crashes, adb+logcat will show you the stack trace, which will point to the exact line where your app crashed, and why!

http://developer.android.com/intl/zh-CN/guide/developing/tools/adb.html#logcat

Brad Hein
+1  A: 

i had the same problem, i solved it looking at your comment about creating a new database.

The onCreate() method is called only when creating the database. If database is allready created (it creates the first time you try the code :), onCreate will not be called the next time you run the emulator. so modifying the sql statement in onCreate() method wont change the table the next time you start the emulator, and you will still have the table that was created the first time you started your emulator and created the database. with this scenario you will have faulty sql statements in you code. second scenario is that you used the adb-sqlite3 console (shell) program and modified the table(s). Database is already created, so onCreate() wont be called - and no matter what code you have to describe the table in you onCreate() the table will be the same as you modified it through shell...

my problem was that i deleted the tables using shell, and expected onCreate to re-create them, but the database was already created, and had no tables anymore.

So, the conclusion is that the first time you create the DATABASE all the tables are created, and if you need to modify them, modify them through shell or delete the database so the onCreate will be called nes time you run your program.

gosh, this text sounds like a infinite loop :) sorry for complicating the answer, im realy realy tiered already... :(

good luck!

sku