vendredi 19 juin 2015

What is wrong with the following code (Android+Sqlite)?

I am quite new to Sqlite (android) and still learning. Please look at the following code and help me find out the mistake.

private static final String TABLE_NAME = "Verse";
private static final String VERSE_ID = "VerseId";
private static final String VERSE_NAME = "Name";
private static final String VERSE_DESCRIPTION = "Description";
private static final String VERSE_NUMBER = "VerseNumber";

private void fillVerses(String chapterId) {

    friends = new ArrayList<Verse>();



    int chapId = Integer.parseInt(chapterId); {value "1" while debugging}
    Cursor friendCursor = database.query(TABLE_NAME, new String[] { VERSE_ID, VERSE_NAME, VERSE_DESCRIPTION,
                    VERSE_NUMBER }, "ChapterId=" + chapId, null, null, null, null);

    friendCursor.moveToFirst();
    if(!friendCursor.isAfterLast()) {
        do {

            String id = String.valueOf(friendCursor.getInt(0));
            String name = friendCursor.getString(1);
            String description = friendCursor.getString(2);
            String verseNumber = friendCursor.getString(3);
            Verse c = new Verse(id,name, description, verseNumber);
            friends.add(c);
        } while (friendCursor.moveToNext());
    }
    friendCursor.close();



}

The problem is here, The debugger on passing this is saying : "The frame isn't available". :

 Cursor friendCursor = database.query(TABLE_NAME, new String[] { VERSE_ID, VERSE_NAME, VERSE_DESCRIPTION,VERSE_NUMBER }, "ChapterId=" + chapId, null, null,    null, null);

Schema : CREATE TABLE Verse ( VerseId INTEGER NOT NULL, Name TEXT NOT NULL, Description TEXT NOT NULL, VerseNumber NVARCHAR(5) NOT NULL, ChapterId INTEGER NOT NULL, PRIMARY KEY(VerseId), FOREIGN KEY(ChapterId) REFERENCES [Chapter] ( [ChapterId] ) ON DELETE NO ACTION ON UPDATE NO ACTION );

There are values present in the DB for ChapterId - 1 for table Verse.

Please help.

Aucun commentaire:

Enregistrer un commentaire