使用Cursor的sqlite更新方法

时间:2014-12-11 00:04:31

标签: android android-sqlite

您好我正在为我的android项目创建一个sqlite帮助文件。我已经找到了几个关于这样做的教程但我遇到了从sqlite数据库中检索值的问题。我收到以下错误消息:"无法解析构造函数"

Event getEvent(int id) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(TABLE_EVENTS, new String[] { KEY_ID, KEY_EVENTNAME, KEY_EVENTTIME,
          KEY_EVENTDATE, KEY_EVENTLOCATION, KEY_EVENTADDRESS1, KEY_EVENTADDRESS2, KEY_EVENTCITY, KEY_EVENTSTATE, KEY_EVENTZIP, KEY_EVENTTYPE },
            KEY_ID + "=?", new String[] {String.valueOf(id)}, null, null, null, null);

    if (cursor != null)
        cursor.moveToFirst();

    Event event = new Event(Integer.parseInt(cursor.getString(0)), cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4),
            cursor.getString(5), cursor.getString(6),cursor.getString(7), cursor.getString(8), cursor.getString(9),
            cursor.getString(10), cursor.getString(11));

    //return event
    return  event;
}

错误出现在以Event event = new Event ....

开头的语句中

我不确定我是否需要每个表列的cursor.getString(n)?

任何帮助都会很棒。

感谢。

添加事件文件

  //empty contructor
public Event(){

}

public Event(int id, String _eventName, String _eventTime, String _eventDate, String _eventLocation, String _eventAddress1, String _eventAddress2, String _eventCity, String _eventState, int _eventZip, String _eventType) {
    this._id = id;
    this._eventName = _eventName;
    this._eventTime = _eventTime;
    this._eventDate = _eventDate;
    this._eventLocation = _eventLocation;
    this._eventAddress1 = _eventAddress1;
    this._eventAddress2 = _eventAddress2;
    this._eventCity = _eventCity;
    this._eventState = _eventState;
    this._eventZip = _eventZip;
    this._eventType = _eventType;
}

public  Event(String _eventName, String _eventTime, String _eventDate, String _eventLocation, String _eventAddress1, String _eventAddress2, String _eventCity, String _eventState, int _eventZip, String _eventType) {
    this._eventName = _eventName;
    this._eventTime = _eventTime;
    this._eventDate = _eventDate;
    this._eventLocation = _eventLocation;
    this._eventAddress1 = _eventAddress1;
    this._eventAddress2 = _eventAddress2;
    this._eventCity = _eventCity;
    this._eventState = _eventState;
    this._eventZip = _eventZip;
    this._eventType = _eventType;
}

1 个答案:

答案 0 :(得分:0)

谢谢@Selvin和@Pier这是问题的一部分我有太多的参数而另一部分是我没有意识到你需要cursor.getInt()而不是cursor.getString用于整数。

再次感谢