获取sqlite异常的数据不会出现在文本视图中

时间:2015-01-10 12:21:04

标签: android sqlite

如果这个问题重复抱歉,我是android新手。 我的问题是我有一个ProjectManagerfargment我有一个微调器属于employeefragment和一些textview,我从datahandler方法设置数据,所以,我选择微调器字段,并根据我在textview中设置值但我是得到像列不存在的日期列。谢谢,请有人建议我说对了。

这是我的数据库初始化,表创建和方法代码

private static final String KEY_TASKID1 = "idtask1";
private static final String KEY_TASKNAME1 = "taskname1";
private static final String KEY_TASKEID1 = "taskeid1";
private static final String KEY_TASKPID1 = "taskpid1";
public static final String KEY_STARTDATE1 = "startdate";
public static final String KEY_ENDDATE1 = "enddate1";

String CREATE_TASKS_TABLE = "CREATE TABLE " + TABLE_TASKS + "("
            + KEY_TASKID1 + " INTEGER PRIMARY KEY," + KEY_TASKNAME1 + " TEXT,"
            + KEY_TASKEID1 + " TEXT," + KEY_TASKPID1 + " TEXT," + KEY_STARTDATE1 + "TEXT," + KEY_ENDDATE1 +"TEXT"+ ")";

public Task getProjectmanagerName(String id) {
    SQLiteDatabase db = this.getWritableDatabase();
    Task task = new Task();
    String query ="SELECT  " + KEY_TASKNAME1 +", " +KEY_TASKPID1 +","+ KEY_STARTDATE1 +","+ KEY_ENDDATE1 +" FROM " + TABLE_TASKS+ " WHERE " + KEY_TASKEID1 + "=" + id;
    Cursor cursor = db.rawQuery(query, null);
    if (cursor.moveToFirst()) {
        do {
            task.setName(cursor.getString(0));
            task.setPid(cursor.getString(1));
            task.setStartdate(cursor.getString(2));
            task.setEnddate(cursor.getString(3));
        } while (cursor.moveToNext());
    }
    return task;

}

这是我的片段类代码

m_name.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            selectedManager =Integer.toString(((Employee)con.get(position)).getID());
            Log.i("projectid",selectedManager);
            task=db.getProjectmanagerName(selectedManager);
             manager.setText(task.getName());
             project.setText(task.getPid());
             start.setText(task.getStartdate());
             end.setText(task.getEnddate());
        }

来自Log cat的这个

01-10 05:58:37.889: E/AndroidRuntime(1839): android.database.sqlite.SQLiteException: no such column: startdate (code 1): , while compiling: SELECT  taskname1, taskpid1,startdate,enddate FROM Task WHERE taskeid1=1

2 个答案:

答案 0 :(得分:1)

你在这里错过了一些空格:

KEY_STARTDATE1 + "TEXT," + KEY_ENDDATE1 +"TEXT"+ ")";

更改为

KEY_STARTDATE1 + " TEXT," + KEY_ENDDATE1 +" TEXT"+ ")";

并卸载您的应用,以便重新创建数据库。

答案 1 :(得分:0)

更改此

public static final String KEY_STARTDATE1 = "startdate1";

public static final String KEY_STARTDATE1 = "startdate";

如果错误保持不变,请更新数据库版本并运行。