公共游标getAll错误Android

时间:2011-02-02 14:32:30

标签: android

我正在为我的大学做最后一个项目,我遇到了一个奇怪的错误。 在Eclipse中它表示一切正常,但是当我在数据库适配器中尝试访问此函数时运行程序时程序崩溃:

public Cursor getAllProjectsCursor() {
    return db.query(DATABASE_TABLE,
                    new String[] {
                            KEY_ID,
                            KEY_PROJ_NAME,
                            KEY_BEG_DATE
                    }, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null);

}

但是,如果我只是这样,程序正常运行:

public Cursor getAllProjectsCursor() {
    return db.query(DATABASE_TABLE,
                    new String[] {
                            KEY_ID,
                            KEY_PROJ_NAME
                    }, 
                    null, 
                    null, 
                    null, 
                    null, 
                    null);
}

我想传递所有列值,我认为所有建筑都很好。所有列都是一样的。

你能帮助我吗?


在调试中它说:

INFO/Database(677): sqlite returned: error code = 1, msg = no such column: beg_date

在我的代码中,我有:

public class PMDBAdapter {

    private static final String DATABASE_NAME = "PocketManager.db";
        private static final String DATABASE_TABLE = "Projects";
            private static final int DATABASE_VERSION = 1;
            private SQLiteDatabase db;
            public static final String KEY_ID = "_id";
            public static final String KEY_PROJ_NAME = "proj_name";
            public static final int PROJ_NAME_COLUMN = 2;
            public static final String KEY_AREA = "proj_area";
            public static final int AREA_COLUMN = 3;
            public static final String KEY_BEG_DATE = "beg_date";
            public static final int BEG_DATE_COLUMN = 4;
            public static final String KEY_END_DATE = "end_date";
            public static final int END_DATE_COLUMN = 5;
            public static final String KEY_PERC = "perc";
            public static final int PERC_COLUMN = 6;

            private final Context context;
            private ProjDBOpenHelper dbHelper;

    private static final String DATABASE_CREATE = "create table " +
    DATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " 
           + KEY_PROJ_NAME + " text not null, "
           + KEY_AREA + "text not null, " 
           + KEY_BEG_DATE + "long, "
           + KEY_END_DATE + "long, "
           + KEY_PERC + " integer);";

2 个答案:

答案 0 :(得分:3)

变化

return db.query(DATABASE_TABLE, new String[] {
                     KEY_ID,
                     KEY_PROJ_NAME
                     KEY_BEG_DATE}, 
                            null, 
                            null, 
                            null, 
                            null, 
                            null);

        }

return db.query(DATABASE_TABLE, new String[] {
                     KEY_ID,
                     KEY_PROJ_NAME,
                     KEY_BEG_DATE}, 
                            null, 
                            null, 
                            null, 
                            null, 
                            null);

        }

Eclipse通常不会接收数据库查询字符串中的错误。

答案 1 :(得分:-1)

public Cursor getAllDataDays() {
    SQLiteDatabase db = this.getWritableDatabase();
    String selectQuery = "SELECT * FROM " + TABLE_MYBUDGETWITHDAYS;
    return db.rawQuery(selectQuery, null);
    }