Having a simple database problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Having a simple database problem

Postby gauntface » Tue Nov 11, 2008 11:32 am

Hey everyone

Im currently playing around with the sqlite database with android, well trying to, and the main problem I'm having is by using

Code: Select all
mDatabase = SQLiteDatabase.openDatabase("/data/data/com.overworld/databases/overworld.db", null, SQLiteDatabase.CREATE_IF_NECESSARY);


It gets and SQLite Exception

android.database.sqlite.SQLiteException: unable to open database file

Am I doing something drastically wrong? Because to me this make perfect sense and can't see why it wouldn't let me do this, do I need to use the SQLiteOpenHelper or set some sort of permission to write files?

Sorry that this is such a simple problem I'm very new to android and databases sooo I'm kinda in over my head lol

Many Thanks
Gaunt
Last edited by gauntface on Tue Nov 11, 2008 11:40 am, edited 1 time in total.
gauntface
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Nov 11, 2008 11:16 am

Top

Postby MrSnowflake » Tue Nov 11, 2008 11:34 am

What does you log say?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby gauntface » Tue Nov 11, 2008 11:39 am

Code: Select all
11-11 10:27:45.915: ERROR/Database(383): sqlite3_open_v2("/data/data/com.overworld/databases/overworld.db", &handle, 6, NULL) failed


Which doesn't seem to help me work out the problem.

Do I need to manually create the directory databases in my package directory?

Note: Just changed trial to overworld - project name so apologies for that - I'll edit code in the original post

Edit : Full Log - Just found how to clear log in eclipse


Code: Select all
11-11 10:53:23.815: DEBUG/dalvikvm(563): Calling exit(1)
11-11 10:53:23.865: INFO/ActivityManager(51): Process com.overworld (pid 563) has died.
11-11 10:53:23.865: DEBUG/Zygote(23): Process 563 exited cleanly (1)
11-11 10:53:23.885: INFO/WindowManager(51): WIN DEATH: Window{434ae820 com.overworld/com.overworld.overworld}
11-11 10:53:24.224: DEBUG/AndroidRuntime(580): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
11-11 10:53:24.224: DEBUG/AndroidRuntime(580): CheckJNI is ON
11-11 10:53:24.385: DEBUG/AndroidRuntime(580): --- registering native functions ---
11-11 10:53:24.395: INFO/jdwp(580): received file descriptor 20 from ADB
11-11 10:53:25.174: DEBUG/PackageParser(51): Scanning package: /data/app/vmdl42914.tmp
11-11 10:53:25.264: WARN/PackageManager(51): Attempt to re-install com.overworld without first uninstalling.
11-11 10:53:25.274: INFO/installd(27): unlink /data/dalvik-cache/data@app@vmdl42914.tmp@classes.dex
11-11 10:53:25.284: DEBUG/AndroidRuntime(580): Shutting down VM
11-11 10:53:25.284: DEBUG/dalvikvm(580): DestroyJavaVM waiting for non-daemon threads to exit
11-11 10:53:25.305: INFO/dalvikvm(580): DestroyJavaVM shutting VM down
11-11 10:53:25.315: DEBUG/dalvikvm(580): HeapWorker thread shutting down
11-11 10:53:25.315: DEBUG/dalvikvm(580): HeapWorker thread has shut down
11-11 10:53:25.315: DEBUG/jdwp(580): JDWP shutting down net...
11-11 10:53:25.315: DEBUG/jdwp(580): +++ peer disconnected
11-11 10:53:25.315: INFO/dalvikvm(580): Debugger has detached; object registry had 1 entries
11-11 10:53:25.315: DEBUG/dalvikvm(580): VM cleaning up
11-11 10:53:25.325: DEBUG/dalvikvm(580): LinearAlloc 0x0 used 529492 of 4194304 (12%)
11-11 10:53:25.625: DEBUG/dalvikvm(51): GC freed 5097 objects / 328496 bytes in 334ms
11-11 10:53:25.725: DEBUG/AndroidRuntime(588): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
11-11 10:53:25.725: DEBUG/AndroidRuntime(588): CheckJNI is ON
11-11 10:53:25.884: DEBUG/AndroidRuntime(588): --- registering native functions ---
11-11 10:53:25.894: INFO/jdwp(588): received file descriptor 20 from ADB
11-11 10:53:26.665: DEBUG/PackageParser(51): Scanning package: /data/app/vmdl42915.tmp
11-11 10:53:26.755: DEBUG/PackageManager(51): Removing package com.overworld
11-11 10:53:26.755: DEBUG/PackageManager(51):   Activities: com.overworld.overworld
11-11 10:53:26.765: DEBUG/PackageManager(51): Scanning package com.overworld
11-11 10:53:26.765: INFO/PackageManager(51): /data/app/vmdl42915.tmp changed; unpacking
11-11 10:53:26.774: DEBUG/installd(27): DexInv: --- BEGIN '/data/app/vmdl42915.tmp' ---
11-11 10:53:26.924: DEBUG/dalvikvm(594): DexOpt: load 17ms, verify 20ms, opt 1ms
11-11 10:53:26.934: DEBUG/installd(27): DexInv: --- END '/data/app/vmdl42915.tmp' (success) ---
11-11 10:53:26.934: DEBUG/PackageManager(51):   Activities: com.overworld.overworld
11-11 10:53:27.004: INFO/installd(27): move /data/dalvik-cache/data@app@vmdl42915.tmp@classes.dex -> /data/dalvik-cache/data@app@com.overworld.apk@classes.dex
11-11 10:53:27.004: DEBUG/PackageManager(51): New package installed in /data/app/com.overworld.apk
11-11 10:53:27.124: DEBUG/AndroidRuntime(588): Shutting down VM
11-11 10:53:27.124: DEBUG/dalvikvm(588): DestroyJavaVM waiting for non-daemon threads to exit
11-11 10:53:27.134: DEBUG/ActivityManager(51): Uninstalling process com.overworld
11-11 10:53:27.144: INFO/dalvikvm(588): DestroyJavaVM shutting VM down
11-11 10:53:27.154: DEBUG/dalvikvm(588): HeapWorker thread shutting down
11-11 10:53:27.154: DEBUG/dalvikvm(588): HeapWorker thread has shut down
11-11 10:53:27.154: DEBUG/jdwp(588): JDWP shutting down net...
11-11 10:53:27.154: DEBUG/jdwp(588): Got wake-up signal, bailing out of select
11-11 10:53:27.154: INFO/dalvikvm(588): Debugger has detached; object registry had 1 entries
11-11 10:53:27.154: DEBUG/dalvikvm(588): VM cleaning up
11-11 10:53:27.184: ERROR/dalvikvm(588): pthread_setspecific failed, err=22
11-11 10:53:27.184: DEBUG/dalvikvm(588): LinearAlloc 0x0 used 529492 of 4194304 (12%)
11-11 10:53:27.365: DEBUG/dalvikvm(91): GC freed 91 objects / 3976 bytes in 216ms
11-11 10:53:27.595: DEBUG/dalvikvm(51): GC freed 4501 objects / 246848 bytes in 281ms
11-11 10:53:27.715: DEBUG/AndroidRuntime(600): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
11-11 10:53:27.725: DEBUG/AndroidRuntime(600): CheckJNI is ON
11-11 10:53:27.954: DEBUG/AndroidRuntime(600): --- registering native functions ---
11-11 10:53:27.964: INFO/jdwp(600): received file descriptor 20 from ADB
11-11 10:53:28.755: DEBUG/ActivityManager(51): Uninstalling process com.overworld
11-11 10:53:28.765: INFO/ActivityManager(51): Starting activity: Intent { flags=0x10000000 comp={com.overworld/com.overworld.overworld} }
11-11 10:53:28.804: DEBUG/AndroidRuntime(600): Shutting down VM
11-11 10:53:28.804: DEBUG/dalvikvm(600): DestroyJavaVM waiting for non-daemon threads to exit
11-11 10:53:28.824: INFO/dalvikvm(600): DestroyJavaVM shutting VM down
11-11 10:53:28.824: DEBUG/dalvikvm(600): HeapWorker thread shutting down
11-11 10:53:28.824: DEBUG/dalvikvm(600): HeapWorker thread has shut down
11-11 10:53:28.824: DEBUG/jdwp(600): JDWP shutting down net...
11-11 10:53:28.824: DEBUG/jdwp(600): +++ peer disconnected
11-11 10:53:28.824: INFO/dalvikvm(600): Debugger has detached; object registry had 1 entries
11-11 10:53:28.844: INFO/ActivityManager(51): Start proc com.overworld for activity com.overworld/.overworld: pid=607 uid=10017 gids={3003}
11-11 10:53:28.844: DEBUG/dalvikvm(600): VM cleaning up
11-11 10:53:28.854: DEBUG/dalvikvm(600): LinearAlloc 0x0 used 541284 of 4194304 (12%)
11-11 10:53:28.874: ERROR/dalvikvm(600): pthread_setspecific failed, err=22
11-11 10:53:28.944: INFO/jdwp(607): received file descriptor 10 from ADB
11-11 10:53:29.084: WARN/ActivityThread(607): Application com.overworld is waiting for the debugger on port 8100...
11-11 10:53:29.094: INFO/System.out(607): Sending WAIT chunk
11-11 10:53:29.114: INFO/dalvikvm(607): Debugger is active
11-11 10:53:29.304: INFO/System.out(607): Debugger has connected
11-11 10:53:29.304: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:29.508: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:29.712: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:29.917: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:30.114: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:30.324: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:30.524: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:30.728: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:30.932: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:31.134: INFO/System.out(607): waiting for debugger to settle...
11-11 10:53:31.334: INFO/System.out(607): debugger has settled (1339)
11-11 10:53:31.525: ERROR/Database(607): sqlite3_open_v2("/data/data/com.overworld/databases/overworld.db", &handle, 6, NULL) failed
11-11 10:53:31.984: WARN/Maps(607): Couldn't restore map info, data == null
11-11 10:53:32.505: INFO/MapActivity(607): Handling network change notification:CONNECTED
11-11 10:53:32.505: ERROR/MapActivity(607): Couldn't get connection factory client
11-11 10:53:32.944: DEBUG/dalvikvm(607): GC freed 2318 objects / 237504 bytes in 72ms
11-11 10:53:33.244: INFO/ActivityManager(51): Displayed activity com.overworld/.overworld: 4480 ms
11-11 10:53:38.615: DEBUG/dalvikvm(91): GC freed 918 objects / 47008 bytes in 68ms

gauntface
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Nov 11, 2008 11:16 am

Postby MrSnowflake » Tue Nov 11, 2008 12:07 pm

Does the directory databases exist?

And if that doesn't help try:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mDatabase = SQLiteDatabase.openDatabase("databases/overworld.db", null, SQLiteDatabase.CREATE_IF_NECESSARY);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby gauntface » Tue Nov 11, 2008 4:31 pm

Thanks for your help mr snowflake but I just spotted the notepad tutorial and picked out bits from that so managed to get it working. I was just completely heading up the wrong road.

Now I have problems with Cursors from when I query the database.

I hardcore

c.getString(1)

and I am given the exception

11-11 15:25:23.925: VERBOSE/overworld(321): Problem occured reading query android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5

which I can't see where it's getting -1 from but I'll hopefully figure it out.

Thanks again for all your help
gauntface
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Nov 11, 2008 11:16 am

Postby manimal » Sun Jan 11, 2009 2:45 am

Hi, I'm having the same problem opening the database. How were you able to fix your problem?
manimal
Freshman
Freshman
 
Posts: 2
Joined: Sun Jan 11, 2009 2:36 am

Top

Postby guian » Sun Jan 11, 2009 12:44 pm

it's a good question manimal !

gauntface don't forget to put the answer to any probleme here when you get it please ;) it can help many poeple!
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Postby misato » Mon Jan 12, 2009 12:15 pm

I don't know if this helps but when i fetch Cursor's data, i put:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String description = c.getString(c.getColumnIndex(NAME_OF_COLUMN));
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

just in case it gets mad with indexes ;)
misato
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 07, 2009 11:55 am

Postby MrSnowflake » Mon Jan 12, 2009 1:05 pm

gauntface wrote:11-11 15:25:23.925: VERBOSE/overworld(321): Problem occured reading query android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5

which I can't see where it's getting -1 from but I'll hopefully figure it out.
Because you probably didn't move the cursor to the first entry. Which you always should do: if(cursor.moveToFirst()) //cursor is ready.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Re:

Postby damninggodson » Thu May 20, 2010 8:52 am

MrSnowflake wrote:
gauntface wrote:11-11 15:25:23.925: VERBOSE/overworld(321): Problem occured reading query android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5

which I can't see where it's getting -1 from but I'll hopefully figure it out.
Because you probably didn't move the cursor to the first entry. Which you always should do: if(cursor.moveToFirst()) //cursor is ready.



with
Code: Select all
if(cursor.moveToFirst())
, the exception is eliminated :)

but why? how does it work, MrSnowflake?
damninggodson
Developer
Developer
 
Posts: 36
Joined: Thu Mar 25, 2010 3:36 am

Re: Having a simple database problem

Postby MrSnowflake » Thu May 20, 2010 9:20 am

Cursor objects will always be positioned before the first entry! So you have to manually move to the first object. This makes it possible to do a simple check to see whether the Cursor object is empty or not. (as you sippet shows).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Re: Having a simple database problem

Postby damninggodson » Fri May 21, 2010 1:50 am

MrSnowflake wrote:Cursor objects will always be positioned before the first entry! So you have to manually move to the first object. This makes it possible to do a simple check to see whether the Cursor object is empty or not. (as you sippet shows).



gottcha... thx!
damninggodson
Developer
Developer
 
Posts: 36
Joined: Thu Mar 25, 2010 3:36 am

Re: Having a simple database problem

Postby edouard.lopez » Tue Jul 12, 2011 12:34 pm

How did you solve your issue ?
I can't figure out the problem.

Cheers,
Ed
edouard.lopez
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jul 12, 2011 12:27 pm

Re: Having a simple database problem

Postby bugaudin » Tue Feb 21, 2012 12:20 pm

Hi, gauntface.

So how did you resolve your first issue?
bugaudin
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Nov 16, 2011 10:13 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests