Je suis en train de mettre à niveau d'AndroidAnnotations 3.3.2 à la version 4.0.0 et avoir un problème avec ORMLite pour fonctionner après la mise à niveau. Après mise à niveau vers 4.0.0 et construire le projet, je reçois le message d'erreur: « erreur: ne peut pas trouver la classe de symbole OrmLiteDao » Et cette partie de code est marqué en rouge:Comment faire pour ajuster AndroidAnnotations 3.x compatible code ORMLite pour AndroidAnnotations 4.0.0
@OrmLiteDao(helper = DatabaseHelper.class)
ContactDao mContactDao;
Mon ancienne classe (es) qui fonctionne parfaitement avec AndroidAnnotations 3.3.2 ressemble à quelque chose comme ceci:
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;
}
}
Et ma classe ContactDao est relativement vide depuis que j'ai les méthodes toutes dans la classe 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);
}
}
Selon le AndroidAnnotations Wiki (https://github.com/excilys/androidannotations/wiki/Ormlite) Je dois changer le code à ceci:
@EActivity
public class MyActivity extends Activity {
@OrmLiteDao(helper = DatabaseHelper.class)
void setUserDao(UserDao userDao){
// do something with userDao
}
}
Il est pas clair pour moi que je dois ajuster mon code ci-dessus au nouveau format (ci-dessous) pour pour le faire fonctionner avec AndroidAnnotations 4.0.0. Quelqu'un pourrait-il me montrer comment je dois ajuster mon code pour le rendre compatible avec AndroidAnnotations 4.0.0?
Merci.
Puisque '@ OrmLiteDao' fait partie du plugin ormlite (comme décrit sur la page wiki que vous liez), avez-vous ajouté le plugin comme dépendance? Autrement dit, avez-vous ajouté 'compile 'org.androidannotations: ormlite: 4.0.0'' à votre' build.gradle'? Dans la version 3.3.2, l'annotation faisait toujours partie de l'API principale, mais le projet a adopté une approche plus modulaire depuis lors. –