The default database location in internal storage is not under "files", but rather under "databases".

Second, the "/data/data/<package name>" part may differ from device to device, e.g. on the Galaxy S it's something like "/dbdata/databases/<package name>" (IIRC).

So - if you're trying to open a database in internal memory, just use Context.openOrCreateDatabase, and Context.getDatabasePath if needed.

For external memory, use SQLiteDatabase.openOrCreateDatabase. I wouldn't recommend it though, as the memory card can become unmounted at any time, or may not be reliable (bad memory card, loose in the socket, etc.)

If necessary, take a look at the source for the framework's SQLiteOpenHelper.

-- Kostya

06.07.2011 17:51, NikolaMKD пишет:
Here is my method where insertion is done in Main
public void addBuildingContent(Bundle addDb, String DBNAME)
        {
                if(addDb != null&&  addDb.getBoolean("add city db", true))
                {
         SQLiteDatabase db = null;
         Database dbobj = new Database(Map.this.getBaseContext(),
DBNAME, true);

        try {
                  dbobj.createDatabase();
                } catch (IOException ioe) {
                        throw new Error("Unable to create database");
                }
                try {
                        dbobj.openDatabase();
                        Log.i("DBOPEN","OPEEEEN");
                }catch(SQLException sqle){
                        throw sqle;
                }
                db = 
SQLiteDatabase.openDatabase("/data/data/com.android.me/files/
city.db", null, SQLiteDatabase.OPEN_READWRITE);
                db.setLockingEnabled(true);
                if(db.isOpen())
                {Log.i("DB OPEN","DB OPEEEEN");}
                if(db.isDbLockedByCurrentThread())
                {
                        Log.i("DB LOCKED","BY THIS THREAD");
                }
                if(db.isReadOnly())
                {
                        Log.i("DB ","READ ONLYYYYYs");
                }

                Log.i("DBOPEN",db.toString());

         dbobj.closedb();

                vrednosti = new ContentValues();
                vrednosti.put("_id","?");
                        vrednosti.put("ime", "\""+addDb.getString("ime")+"\"");
                        vrednosti.put("lat",addDb.getInt("Lat"));
                        vrednosti.put("long",addDb.getInt("Long"));
                         db.insert("banks", null, vrednosti);
                         db.close();

                }
        }
---------------------------------------------------------------------------------------------------------------------------------

http://pastebin.com/91pcE60L<--- this is my Database.class
----------------------------------------------------------------------------------------------------------------
This is the error from the logcat:
07-06 13:39:04.305: INFO/INDEX CAT(560): 1
07-06 13:39:04.315: ERROR/Database(560): sqlite3_open_v2("/data/data/
com.android.me/files/city.db",&handle, 2, NULL) failed
07-06 13:39:04.315: INFO/GET WRITABLE(560): VLEZ
07-06 13:39:04.325: ERROR/Database(560): sqlite3_open_v2("/data/data/
com.android.me/files/city.db",&handle, 2, NULL) failed
07-06 13:39:04.325: INFO/DBOPEN(560): OPEEEEN
07-06 13:39:04.325: ERROR/Database(560): sqlite3_open_v2("/data/data/
com.android.me/files/city.db",&handle, 2, NULL) failed
07-06 13:39:04.334: DEBUG/AndroidRuntime(560): Shutting down VM
07-06 13:39:04.334: WARN/dalvikvm(560): threadid=3: thread exiting
with uncaught exception (group=0x4001b188)
07-06 13:39:04.344: ERROR/AndroidRuntime(560): Uncaught handler:
thread main exiting due to uncaught exception
07-06 13:39:04.354: ERROR/AndroidRuntime(560):
android.database.sqlite.SQLiteException: unable to open database file
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:
1697)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:
738)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
walk.me.Map.addBuildingContent(Map.java:1294)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at walk.me.Map
$Marker$1$6.onTouch(Map.java:1127)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.View.dispatchTouchEvent(View.java:3705)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
1107)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.app.Dialog.dispatchTouchEvent(Dialog.java:643)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.os.Looper.loop(Looper.java:123)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-06 13:39:04.354: ERROR/AndroidRuntime(560):     at
dalvik.system.NativeStart.main(Native Method)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have saved the external SQLite databases in /data/data/
com.android.me/files, which does not cause problems when reading from
database. But when I try to write in database this error happens. What
I'm doing wrong?

Thank you.


--
Kostya Vasilyev

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to