Null Pointer Exception on simple People query

by kingkung » Wed, 07 May 2008 01:29:29 GMT


Sponsored Links
 Hey all,

Not sure what I"m doing wrong...

I have a dbHelper which makes a query for all of the rows in People.

When I do this query in my first activity, initializing dbHelper with
that activity, I get all the people as I am supposed to.

However, when I do the query in my second activity, with its own
dbHelper initialized on its own activity, the cursor is assigned
null!!  I call cursor.first(), and the app throws an NPE.

Nothing about the People database has changed... the table is the same
between the first and second activity.

Anyone know what is going on???

Thanks,

James

--~--~---------~--~----~------------~-------~--~----~



Null Pointer Exception on simple People query

by Ahmet A. Akin » Wed, 07 May 2008 03:03:23 GMT


 maybe you should write the stack trace.




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Null Pointer Exception on simple People query

by kingkung » Wed, 07 May 2008 15:27:00 GMT


 I'm sorry, it's not that it returs a null pointer exception, it's that
when I query the People database on my second activity, cursor.first()
returns false!!!  All of the people are still in the database
(nothing's changed)... why would the query from my first activity
return the list of People, and an identical query return nothing?

I'm very puzzled.

Thanks,

James




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. creating and opening sqlitedb on sdcard for api7

hi all,
I have a small problem with my code, I am trying to create (if that
does not exist) and open connection to sqlite but it fails to open. Im
doing that cos I know that my db can be big and may not fit into
mobile local storage.

1. I get path to external storage and get the full path to sqlite file
(both rootFolder (ie, "sqlitedb") and name (ie. "mydb.db") may not
exists on sd card)
private String getExternal(String rootFolder, String name) {
        final String externalStorageState =
Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(externalStorageState)) {
            externalReadOnly = false;
        } else if
(Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState)) {
            externalReadOnly = true;
        } else {
            throw new SQLiteDiskIOException("couldn't obtain external
data store");
        }
        return new
StringBuilder(Environment.getExternalStorageDirectory().
                getPath()).append(File.pathSeparator).
                append(rootFolder).
                append(File.pathSeparator).
                append(name).
                toString();
    }
2. im trying to open the sqlite db with given path
final String path = getExternal(root, name);
Log.d(TAG, "opening readonly database at " + path);
db = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READWRITE & SQLiteDatabase.CREATE_IF_NECESSARY);

but this is throwing exception
D/SqliteExternalHelper(  362): opening writable database at /
sdcard:db:my_external_db.db
E/Database(  362): sqlite3_open_v2("/sdcard:db:my_external_db.db",
&handle, 2, NULL) failed
D/AndroidRuntime(  362): Shutting down VM
W/dalvikvm(  362): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime(  362): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  362): android.database.sqlite.SQLiteException:
unable to open database file
E/AndroidRuntime(  362):        at
android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
E/AndroidRuntime(  362):        at
android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:
1697)
E/AndroidRuntime(  362):        at
android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:
738)
E/AndroidRuntime(  362):        at
info.kamiseq.db.SqliteExternalHelper.getWritable(SqliteExternalHelper.java:
126)
E/AndroidRuntime(  362):        at
info.kamiseq.db.SqliteExternalHelper.getWritable(SqliteExternalHelper.java:
97)

I am a bit confused about how this should work,
thank for help.

-- 

2. what kind of Android Virtual Device can be used as the emulator for ADP2

Hi all,

I am using the Android Dev Phone 2 (Google IO Phone). But I think it's
more convenient to use the Android emulator for debuging and then
flash to the phone. But I have a problem that when I use my own
customized kernel image to boot the phone, everything is fine, but
when use the same kernel image to boot the emulator, it failed without
any report in "-show-kernel" and even no response. The command I used
is as follows:
1.boot phone to fastboot mode
2.fastboot -boot <new Kernel Image>
  the phone works fine
1. emulator -kernel <new kernel Image> -show-kernel -avd
MyAndroidEmulator
No response...

I have try several kinds of AVD, no one works. Also I export the
config file from the emulator and use the config file to rebuild the
kernel source code. That also doesn't work. When I use the kernel in
"myandroid/prebuild/android-arm/kernel/kernel-qemu, the emulator boot
successfully. BTW, I use the kernel source code git from "/kernel/
msm.git"---android open-source project.

Because my customized kernel can boot my phone, but can't boot the
emulator, I wonder if the emulator does not match my phone or some
other reasons. Can any one give me some suggestions? Thank you very
much.

-- 
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

3. CyanogenMod 5.0.8 for Nexus One STABLE!!

4. OOT: LIVE from Balai Kartini

5. OOT: ABG Berjibun

6. TextView/Spannable - Applying Alignment to portion of the text

7. Link Doc To Go Full