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,
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
autoincrement,
"
+ "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
DB.
*/
private static class DatabaseHelper extends SQLiteOpenHelper {

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

@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL(DATABASE_CREATE);
}

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

/**
* 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
calls.
* @throws SQLException if the database can't be opened or
created.



Other Threads

1. computer applications

http://123maza.com/35/market158/

-- 

2. Can i use Android SDK with eclipse plugin for debugging Drivers?

Hi Guys,

Can I use Android SDK with eclipse plugin for debugging Drivers? What is the
problem if it is not possible?

Thanks,
Rahul.

-- 

3. StrictMode

4. IMediaPlaybackService and gingerbread

5. MediaController.MediaPlayerControl for audio

6. Free version to Paid version

7. Regarding gcov using arm-eabi toolchain