views:

335

answers:

1

My Android app is using a database through an API packaged in an external JAR. Since the JAR is opening/updating/closing the SQLite database file, do I need to make sure it uses its own package name instead of my own? Im getting errors where it fails to open the database file and Im guessing its because the package name Im telling it to use is incorrect: should it be using the package name in the JAR file?

Code that is opening the database:

    public AndroidSQLiteDataStore() throws SQLiteException {
        Logger logger = LoggerFactory.getDefaultInstance();
        logger.information(TAG, "OPEN CONNECTION TO DATABASE " + Config.BN_ANDROID_DB_PATH);
        try {
            this.db = SQLiteDatabase.openDatabase(Config.ANDROID_DB_PATH, null, SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE);
        } catch (SQLiteException e) {
            logger.error(TAG, e.toString());
            throw e;
        }
    }

Also tried poking around with the shell:

$ adb shell
$ ls
sqlite_stmt_journals
cache
sdcard
etc
system
sys
sbin
proc
logo.rle
init.sapphire.rc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
$ cd data
$ ls
opendir failed, Permission denied
$ 
A: 

Since the JAR is opening/updating/closing the SQLite database file, do I need to make sure it uses its own package name instead of my own?

JARs don't have package names from an Android standpoint.

CommonsWare
So using the package name of my app in the path should work right?I get an error when I try to open /data/data/mypackagename/databases/locker.db and I dont understand why.
Eno
We can't readily help with errors without seeing the error in question. Use `adb logcat`, DDMS, or the DDMS perspective in Eclipse to take a look at the Java stack trace. If that doesn't clear up the matter directly, edit your question, post the stack trace there, and if you think of it, add a comment onto this chain here so StackOverflow pings me that there's been an update (I don't think I'll find out if you just edit the issue).
CommonsWare
Eno
Q1. Is the code trying to open the database is in the same process (e.g., part of the same application)? Q2. Can you edit your issue to paste in the code where you are trying to open the database?
CommonsWare
A1. Its part of the same app but the database code lives inside a JAR that I am importing and using in my application.
Eno
A2. I added the code to the original question up top.
Eno
Markdown doesn't work in comments.
Eno
Well, that certainly looks OK. I usually use `SQLiteOpenHelper`, though that may not work in your case. Otherwise, it's not obvious to me why you are getting the error, assuming that static data member's value is correct.
CommonsWare
Basically, the Config class just has static strings for various things like pathnames and URLs. So Im using something like "/data/data/packagename/databases/locker.db" as the path to the database. Should I be using a relative path instead of an absolute one? Or maybe there's a permissions issue Ive overlooked?
Eno
Im assuming that packagename that Im using in the path is what I have in my manifest?
Eno
More importantly, it's the directory where you find the stuff on the emulator (or device, if you could look there). You should see the /data/data/your.package.here directory in the File Manager of DDMS, for example.
CommonsWare
@commonsWare: Eno edited his OP and it seems he has problem even accessing the data folder. I found some posts on SO describing this but on a real device though(no root access).
ccheneson
Is the folder normally accessible from the adb shell? If so, then Im assuming its a permissions problem. I am testing on a real device BTW.
Eno
On the emulator, yes. On a device, no. However, just because adb shell cannot access it does not mean your app cannot access it. When you encounter file-related problems like this, I advise you to roll back to the emulator until you get everything working.
CommonsWare
Hmmm.... using /data/data/packagename/data.db instead seems to work...
Eno