我想从AndroidAnnotations 3.3.2升级到4.0.0版,并且在升级后让ORMLite工作有问题。 我升级到4.0.0后,建设项目中,我得到的错误信息: “错误:无法找到符号类OrmLiteDao” 这部分代码标记为红色:如何调整AndroidAnnotations 3.x compatible ORMLite代码为AndroidAnnotations 4.0.0
@OrmLiteDao(helper = DatabaseHelper.class)
ContactDao mContactDao;
我的老班(ES )与AndroidAnnotations 3.3.2完美的作品看起来是这样的:
public class ContactService {
private final String TAG = getClass().getSimpleName();
@RootContext
Context ctx;
@OrmLiteDao(helper = DatabaseHelper.class)
ContactDao mContactDao;
public Contact getContact(Integer contactId) throws ItemNotFoundException, SQLException {
Contact contact = mContactDao.queryForId(contactId);
if (contact == null) {
Log.e(TAG, "Contact not found in database");
throw new ItemNotFoundException();
}
return contact;
}
public List<Contact> getContacts() throws ItemNotFoundException, SQLException {
List<Contact> contact = mContactDao.queryForAll();
if (contact == null) {
Log.e(TAG, "Contacts not found in database");
throw new ItemNotFoundException();
}
return contact;
}
public Contact createContact(Contact contact) throws SQLException {
try {
mContactDao.create(contact);
} catch (SQLException e) {
Log.e(TAG, e.getLocalizedMessage());
}
Log.d(TAG, "New Contact ID: " + contact.getId());
return contact;
}
}
而我的ContactDAO类是比较空的,因为我都在的ContactService类中的方法:
public class ContactDao extends BaseDaoImpl<Contact, Integer> {
public ContactDao(Class<Contact> dataClass) throws SQLException {
super(dataClass);
}
public ContactDao(ConnectionSource connectionSource, Class<Contact> dataClass) throws SQLException {
super(connectionSource, dataClass);
}
public ContactDao(ConnectionSource connectionSource, DatabaseTableConfig<Contact> tableConfig) throws SQLException {
super(connectionSource, tableConfig);
}
public ContactDao(ConnectionSource connectionSource) throws SQLException {
super(connectionSource, Contact.class);
}
}
按照AndroidAnnotations维基(https://github.com/excilys/androidannotations/wiki/Ormlite)我必须要改变的代码如下:
@EActivity
public class MyActivity extends Activity {
@OrmLiteDao(helper = DatabaseHelper.class)
void setUserDao(UserDao userDao){
// do something with userDao
}
}
目前尚不清楚对我,我怎么也得调整我上面的代码到新格式(见下文),以使其与AndroidAnnotations 4.0.0一起工作。任何人都可以告诉我如何调整我的代码,使其与AndroidAnnotations 4.0.0兼容?
谢谢。
由于'@ OrmLiteDao'是ormlite插件的一部分(如链接的wiki页面所述),您是否将该插件添加为依赖项?也就是说,你是否已经将'compile'org.androidannotations:ormlite:4.0.0''添加到'build.gradle'中?在版本3.3.2中,注释仍然是主要API的一部分,但从那时起该项目采取了更加模块化的方法。 –