开发者

Missing jar source attachments, thread exceptions, null pointer exceptions, when trying to read from SQLite database on Android

I'm writing an Android project in Eclipse and running it on a 3.1 tablet.

When I try to fetch a line from my SQLite da开发者_如何学Pythontabase with

int Get(long rowId){
    System.out.println("Works up to here!!!"); //things are fine
    Cursor c = myDbHelper.fetch(rowId); //things are not fine
    ...
}

I get the following in logcat:

Works up to here!!!
threadid=9: thread exiting with uncaught exception (group=0x40142760)
FATAL EXCEPTION: Thread-10
java.lang.NullPointerException 
    at blah blah blah...

And when I debug, that same spot gives me

The JAR file ...\android.jar has no source attachment.

I find neither of these messages helpful. My code works right up until the above line, but doesn't go into fetch() in my DataBaseHelper class. I know that the class (including open(), create(), fetch(), and all that) works because it's from http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ and I wrote another program with the same database file using the same DataBaseHelper class. Short of posting my 900 lines of code for someone to go through and help me out, what should I look for that might be causing this problem?


Of course, it was a stupid little mistake. I had two "myDbHelper"s. Fixed that and now it works!


Where are you instantiating myDbHelper?

The linked-to source code has

DataBaseHelper myDbHelper = new DataBaseHelper();

are you sure you didn't leave this out?

Also, when debugging, the stacktrace is of immense value - the blah blah part you cut out likely points to the exact line where the NPE occurs, which should give you a huge hint as to which reference is null. Sharing this information - what exact line of code of yours it occurs at - makes it much easier for us to help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜