无法使用ConnectionSource和可选的Class参数找到公共构造函数 - ORMLite

时间:2016-10-14 12:00:26

标签: ormlite

我无法让ORMLite工作 - 看了不同的解决方案,但没有一个能为我工作。

这是我的Appointment班级

@DatabaseTable(tableName = Appointment.TABLE_NAME, daoClass = Appointment.class)
public class Appointment {
public static final String TABLE_NAME = "appointments";

public static final String FIELD_ID = "id";
public static final String FIELD_DATE = "date";
public static final String FIELD_FROM = "from";
public static final String FIELD_TO = "to";
public static final String FIELD_TYPE = "type";
public static final String FIELD_STATUS = "status";
public static final String FIELD_DESCRIPTION = "description";

@DatabaseField(columnName = FIELD_ID, id = true)
public int id;
@DatabaseField(columnName = FIELD_DATE, canBeNull = false)
String dateString;
@DatabaseField(columnName = FIELD_FROM, canBeNull = false)
String fromString;
@DatabaseField(columnName = FIELD_TO, canBeNull = false)
String toString;
@DatabaseField(columnName = FIELD_TYPE, canBeNull = false)
String type;
@DatabaseField(columnName = FIELD_STATUS, canBeNull = false)
String status;
@DatabaseField(columnName = FIELD_DESCRIPTION)
String description;

public Appointment(){}
}

和我的DBHelper

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "mydatabase";
private static final int DATABASE_VERSION = 1;

private Dao<Appointment, Integer> mAppointmentDao = null;

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
    try {
        Utils.log("onCreate()");
        TableUtils.createTable(connectionSource, Appointment.class);
    }catch (Exception ex){
        Utils.log("Error creating tables -> " + ex.getMessage());
    }
}

@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion){
    try {
        TableUtils.dropTable(connectionSource, Appointment.class, true);
        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Utils.log("Error onUpgrade() -> " + e.getMessage());
    }
}

public Dao<Appointment, Integer> getAppointmentDao() throws SQLException {
    if (mAppointmentDao == null) {
        mAppointmentDao = getDao(Appointment.class);
    }

    return mAppointmentDao;
}

@Override
public void close() {
    mAppointmentDao = null;
    super.close();
}
}

当我尝试创建约会时出现错误 - 找不到具有ConnectionSource和可选类参数类的公共构造函数.~约会。课上缺少静态?

helper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
    try{
        appointmentDao = helper.getAppointmentDao();

        Appointment a = new Appointment();
        a.dateString = "12 Nov, 2016";
        a.fromString = "14:00";
        a.toString = "14:30";
        a.status = "pending";
        a.type = "video";
        a.description = "Appointment description";
        a.id = 1;
        appointmentDao.create(a);
}catch (SQLException ex){
        Utils.log("Error creating appointment -> " + ex.getMessage());
    }

0 个答案:

没有答案