Program stopped unexpectedly when access database

by iamaelephant » Sun, 05 Oct 2008 20:11:29 GMT

Sponsored Links
 'm brand new to Android development (and mobile development in
general) so please bare with me. I'm trying to write a very simple app
that will display a list of items from a database to get myself
acquainted with the environment. Everything works fine until I try to
access the database. In my main activity class I have a method,
fillData() which creates a new cursor by calling the method
fetchAllEntries() from my database helper class. I have narrowed the
problem down to this method.

If I return null from this method, it works fine. Obviously I don't
want to return null, I want to return a Cursor. I use the following
code in the method:

String[] columns = {KEY_AUTHOR, KEY_ENTRY};
Cursor c = mDb.query(DATABASE_TABLE, columns, null, null, null, null,
return c;

This code is virtually identical to the code in Google's notepad
tutorial. It should work perfectly. It doesn't - the apps just stops
responding. For completeness I'll include some other relevant code
from my database helper class. Please help me with this problem, it
has me tearing my hair out. I can't even do something so basic without
breaking this damn thing.

public class FriendBoxDbAdapter {

public static final String KEY_AUTHOR = "author";
public static final String KEY_ENTRY = "entry";
public static final String KEY_ROWID = "_id";

public static final String TAG = "FriendBoxDbAdapter";

private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;

/* Database creation SQL statement */
private static final String DATABASE_CREATE =
"create table inbox (_id integer primary key
+ "author text not null, entry text not null);";

private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "inbox";
private static final int DATABASE_VERSION = 2;

private final Context mCtx;

* Inner class DatabaseHelper helps us interface with the DB.
* Pretty standard SQLite statements used to initialise/upgrade
private static class DatabaseHelper extends SQLiteOpenHelper {

DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);

public void onCreate(SQLiteDatabase db) {


public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old
db.execSQL("DROP TABLE IF EXISTS inbox");

* Finally, our constructor. Gives us the context for our DB
* to be created and managed.
* @param ctx The context we can work in
public FriendBoxDbAdapter (Context ctx) {
mCtx = ctx;

* Opens our database using Android's getWritableDatabase
* which is required to write to a DB.
* @return this (self reference allows chained initialisation
* @throws SQLException if the database can't be opened or

Other Threads

1. show phone's contact list

Hi, I am new in android, I want to show the phone's contact list, some

Thanks, Oscar


2. How to change developer account associated with app

We were in a bit of a rush to publish our app at first, and my
associate absentmindedly created a developer account under his
personal google account.  Naturally, he doesn't want anyone else to
have access to his google account, but it means only he can access the
developer account.  The only problem here is we have an app published
with a few hundred users.  What I'd like to know is how to migrate the
management of that app over to a different android development

I know one can't change the association between developer account and
google account, that's not what I'm asking about.  I'd just like to
preserve the app feedback that already exists, and not alienate any of
the current users.  Anybody know what I can do?



3. Android Device / API Level matrix ?

4. Receiving/Sending SMS in a particular Port

5. Immediate Need for System/Database Admin

6. How can I update view with onReceive in appWidget?

7. need help on this asap