samedi 6 juin 2015

Android Fill Text String from SQLite Database

I use a string to populate a textview on an listview

String[] text1 = { "Afghanistan", "Algeria" ,"Fred"};

I want to replace the 3 strings in the string array with data from a database. I have tried the following

    String text1[];
    DBAdapter db = new DBAdapter(this);
    db.open();
    Cursor c = db.getAsset3();
    int counter = 0;
    while (c.moveToNext()) {

        text1[counter]=c.getString(0);

    counter++;  
    }

getAsset3 from DBAdapter

public Cursor getAsset3() throws SQLException 
{
    Cursor mCursor =
            db.query(true, "SURVDAT", new String[] {KEY_SR1,KEY_SR2,KEY_SR3,KEY_SR4,KEY_SR5,KEY_SR6,KEY_SR7}, null, null,null, null, null, null);
    if (mCursor != null) {
        //mCursor.moveToFirst();
    }
    return mCursor;
}

When I run the app crashes saying Null PointerException

Any ideas where I'm going wrong?

Any help Appreciated

Mark

Aucun commentaire:

Enregistrer un commentaire