Not able to retrieve items from the database
I am able to create and add items to the database but retrieval from the database is not happening Its showing as no columns found.. A part of the code is as shown ! please help
 db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_QUES + 开发者_StackOverflow社区" TEXT NOT NULL, " +
                KEY_A + " TEXT NOT NULL, " +
                KEY_B + " TEXT NOT NULL, " +
                KEY_C + " TEXT NOT NULL, " +
                KEY_D + " TEXT NOT NULL);"
        );
//adding entry
    public long createEntry(String ques, String a, String b, String c, String d) {
    ContentValues cv = new ContentValues();
    cv.put(KEY_QUES, ques);
    cv.put(KEY_A, a);
    cv.put(KEY_B, b);
    cv.put(KEY_C, c);
    cv.put(KEY_D, d);
    return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
//Retriving an entry
public String getName(long l) throws SQLException{
    String[] columns = new String[]{ KEY_ROWID, KEY_QUES, KEY_A, KEY_B, KEY_C,KEY_D};
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l,     null,  null, null, null);
    if (c != null){
        c.moveToFirst();
        friends.question = c.getString(1);
        friends.a = c.getString(2);
    }
    return null;
}       
try using the edited code for retrieve purpose.
public String getName(long l) throws SQLException{
    String[] columns = new String[]{ KEY_ROWID, KEY_QUES, KEY_A, KEY_B, KEY_C,KEY_D};
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=?",     new String[] {Long.toString(l)},  null, null, null);
    if (c != null){
        c.moveToFirst();
        friends.question = c.getString(1);
        friends.a = c.getString(2);
    }
    return null;
}       
it think you initialize column name
Cursor cur=ourDatabase.query(DATABASE_TABLE, null,null, null,  null, null, null);
to see what table contain exactly.If it contain diffrent column name then use them, May be you have done initialize
like KEY_A="key_a" like this then use 
that orignal value. make sure to use getReadbleDatabase while reading and getWritableDatabase() while inserting
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论