ORMLite错误没有存在databasefield注释

运行我的Android应用程序时出现此错误:

没有字段在类[[Lmodel.Vak;]中有一个DatabaseField注释。

我的class级Vak有注释,所以我真的不明白为什么它仍然给我这个错误。

package model; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "vak") public class Vak { @DatabaseField(generatedId = true, columnName = "vakID", id=true) Long id; @DatabaseField int rij; @DatabaseField int kolom; ... } 

我有一个名为Databasehelper.java的文件,其中扩展了OrmLiteSqLiteOpenHelper,文件如下所示:

 public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // name of the database file for your application -- change to something // appropriate for your app private static final String DATABASE_NAME = "project56.db"; // any time you make changes to your database objects, you may have to // increase the database version private static final int DATABASE_VERSION = 1; private DatabaseType databaseType = new SqliteAndroidDatabaseType(); // the DAO object we use to access the tables private Dao vleugelDao = null; private Dao verdiepingDao = null; private Dao navigatiePuntDao = null; private Dao lokaalDao = null; private Dao rasterDao = null; private Dao vakDao = null; private Dao graafDao = null; private Dao vertexDao = null; private Dao edgeDao = null; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } /** * This is called when the database is first created. Usually you should * call createTable statements here to create the tables that will store * your data. */ @Override public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { try { Log.i(DatabaseHelper.class.getName(), "onCreate"); TableUtils.createTable(connectionSource, Vleugel.class); TableUtils.createTable(connectionSource, Verdieping.class); TableUtils.createTable(connectionSource, NavigatiePunt.class); TableUtils.createTable(connectionSource, Lokaal.class); TableUtils.createTable(connectionSource, Raster.class); TableUtils.createTable(connectionSource, Vak.class); TableUtils.createTable(connectionSource, Graaf.class); TableUtils.createTable(connectionSource, Vertex.class); TableUtils.createTable(connectionSource, Edge.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't create database", e); throw new RuntimeException(e); } } /** * This is called when your application is upgraded and it has a higher * version number. This allows you to adjust the various data to match the * new version number. */ @Override public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { Log.i(DatabaseHelper.class.getName(), "onUpgrade"); TableUtils.dropTable(connectionSource, Vleugel.class, true); TableUtils.dropTable(connectionSource, Verdieping.class, true); TableUtils.dropTable(connectionSource, NavigatiePunt.class, true); TableUtils.dropTable(connectionSource, Lokaal.class, true); TableUtils.dropTable(connectionSource, Raster.class, true); TableUtils.dropTable(connectionSource, Vak.class, true); TableUtils.dropTable(connectionSource, Graaf.class, true); TableUtils.dropTable(connectionSource, Vertex.class, true); TableUtils.dropTable(connectionSource, Edge.class, true); // after we drop the old databases, we create the new ones onCreate(db, connectionSource); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e); throw new RuntimeException(e); } } /** * Returns the Database Access Object (DAO) for the classes It will create * it or just give the cached value. */ public Dao getVleugelDao() throws SQLException { if (vleugelDao == null) { vleugelDao = getDao(Vleugel.class); } return vleugelDao; } public Dao getVerdiepingDao() throws SQLException { if (verdiepingDao == null) { verdiepingDao = getDao(Verdieping.class); } return verdiepingDao; } public Dao getNavigatiePuntDao() throws SQLException { if (navigatiePuntDao == null) { navigatiePuntDao = getDao(NavigatiePunt.class); } return navigatiePuntDao; } public Dao getLokaalDao() throws SQLException { if (lokaalDao == null) { lokaalDao = getDao(Lokaal.class); } return lokaalDao; } public Dao getRasterDao() throws SQLException { if (rasterDao == null) { rasterDao = getDao(Raster.class); } return rasterDao; } public Dao getVakDao() throws SQLException { if (vakDao == null) { vakDao = getDao(Vak.class); } return vakDao; } public Dao getGraafDao() throws SQLException { if (graafDao == null) { graafDao = getDao(Graaf.class); } return graafDao; } public Dao getVertexDao() throws SQLException { if (vertexDao == null) { vertexDao = getDao(Vertex.class); } return vertexDao; } public Dao getEdgeDao() throws SQLException { if (edgeDao == null) { edgeDao = getDao(Edge.class); } return edgeDao; } /** * Close the database connections and clear any cached DAOs. */ @Override public void close() { super.close(); vleugelDao = null; verdiepingDao = null; navigatiePuntDao = null; lokaalDao = null; rasterDao = null; vakDao = null; graafDao = null; vertexDao = null; edgeDao = null; } } 

我还有一个扩展OrmLiteBaseActivity的文件Controller:

 public class Controller extends OrmLiteBaseActivity { Dao vleugelDao; Dao verdiepingDao; Dao navigatiePuntDao; Dao lokaalDao; Dao rasterDao; Dao graafDao; Dao vertexDao; Dao edgeDao; Dao vakDao; // Databasehelper is benodigd voor ORMLite static { OpenHelperManager.setOpenHelperFactory(new SqliteOpenHelperFactory() { public OrmLiteSqliteOpenHelper getHelper(Context context) { return new DatabaseHelper(context); } }); } public Controller() throws SQLException { /** initialiseren van dao */ vleugelDao = getHelper().getVleugelDao(); verdiepingDao = getHelper().getVerdiepingDao(); navigatiePuntDao = getHelper().getNavigatiePuntDao(); lokaalDao = getHelper().getLokaalDao(); rasterDao = getHelper().getRasterDao(); graafDao = getHelper().getGraafDao(); vertexDao = getHelper().getVertexDao(); edgeDao = getHelper().getEdgeDao(); vakDao = getHelper().getVakDao(); } /** * Haalt vleugel idNaam op uit dao object bijv. K1 * * @return Vleugel * @throws java.sql.SQLException */ public Vleugel getVleugel(String vleugelIDNaam) throws java.sql.SQLException { // select * from vleugel where idNaam='{vleugelIDNaam}' QueryBuilder qb = vleugelDao.queryBuilder(); Where where = qb.where(); // the name field must be equal to "foo" where.eq("idNaam", vleugelIDNaam); PreparedQuery preparedQuery = qb.prepare(); List vleugelList = vleugelDao.query(preparedQuery); Log.v("Getvleugel", vleugelList.size() + ""); if (vleugelList.size() == 1) { return vleugelList.get(0); } return null; } public Verdieping getVerdieping(int nummer) throws java.sql.SQLException { // TODO: Met querybuilder query naar db om verdieping te pakken return null; } /** * Haalt navigatiepunt op * * @param naam * @return * @throws java.sql.SQLException */ public NavigatiePunt getNavigatiePunt(String naam) throws java.sql.SQLException { // select * from navigatiepunt where naam='{naam}' QueryBuilder qb = navigatiePuntDao.queryBuilder(); Where where = qb.where(); where.eq("naam", naam); PreparedQuery preparedQuery = qb.prepare(); List navigatieList = navigatiePuntDao .query(preparedQuery); Log.v("GetLokaal", navigatieList.size() + ""); if (navigatieList.size() == 1) { return navigatieList.get(0); } return null; } /** * Get lokaal object op basis van lokaalcode * * @param lokaalcode * @return * @throws java.sql.SQLException */ public Lokaal getLokaal(String lokaalcode) throws java.sql.SQLException { // select * from lokaal where lokaalcode='{lokaalcode}' QueryBuilder qb = lokaalDao.queryBuilder(); Where where = qb.where(); where.eq("lokaalcode", lokaalcode); PreparedQuery preparedQuery = qb.prepare(); List lokaalList = lokaalDao.query(preparedQuery); Log.v("GetLokaal", lokaalList.size() + ""); if (lokaalList.size() == 1) { return lokaalList.get(0); } return null; } } 

所以你对此有什么建议,我应该检查什么?

这被certificate是ORMLite中的一个错误,它在版本4.22中修复了外来对象循环。 ORMLite没有正确处理A有外国字段B的情况,其中外国字段B有一个外地字段回到A ..

http://ormlite.com/releases/

如果这样做或不起作用,请给我发一些直接邮件@Yanny,我会相应地调整这个答案。

你能查一下,在你的数据库中创建表Vak吗? 没有这个表可能是这次崩溃的原因。

提供解决方案可能为时已晚,但这是我的解决方案:
你看到proguard尝试混淆代码,如果你读深度或介绍proguard

  http://proguard.sourceforge.net/FAQ.html 

什么缩小在proguard – >缩小程序,如ProGuard可以分析字节码并删除未使用的类,字段和方法。 所以从这里我们可以假设它正在删除你的对象,因为它不被任何地方使用……
你可能需要这么重? 你需要阻止proguard从进程中推卸出那些方法或对象,所以这就是那条线:
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

这一行将保持proguard从删除我的公共方法和变量..

-keepclassmembers class classpath.** { public *; }
你需要为atlest id写一个列名…因为它会搜索它并且会改变它的名字……所以你需要为主键定义列名id。