当前位置: 首页 > 面试题库 >

ORMLite错误不存在数据库字段注释

仲孙兴旺
2023-03-14
问题内容

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

在类[[Lmodel.Vak;中,没有字段具有DatabaseField注释。

我的班级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<Vleugel, Long> vleugelDao = null;
private Dao<Verdieping, Long> verdiepingDao = null;
private Dao<NavigatiePunt, Long> navigatiePuntDao = null;
private Dao<Lokaal, Long> lokaalDao = null;
private Dao<Raster, Long> rasterDao = null;
private Dao<Vak, Long> vakDao = null;
private Dao<Graaf, Long> graafDao = null;
private Dao<Vertex, Long> vertexDao = null;
private Dao<Edge, Long> 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<Vleugel, Long> getVleugelDao() throws SQLException {
    if (vleugelDao == null) {
        vleugelDao = getDao(Vleugel.class);
    }
    return vleugelDao;
}

public Dao<Verdieping, Long> getVerdiepingDao() throws SQLException {
    if (verdiepingDao == null) {
        verdiepingDao = getDao(Verdieping.class);
    }
    return verdiepingDao;
}

public Dao<NavigatiePunt, Long> getNavigatiePuntDao() throws SQLException {
    if (navigatiePuntDao == null) {
        navigatiePuntDao = getDao(NavigatiePunt.class);
    }
    return navigatiePuntDao;
}

public Dao<Lokaal, Long> getLokaalDao() throws SQLException {
    if (lokaalDao == null) {
        lokaalDao = getDao(Lokaal.class);
    }
    return lokaalDao;
}

public Dao<Raster, Long> getRasterDao() throws SQLException {
    if (rasterDao == null) {
        rasterDao = getDao(Raster.class);
    }
    return rasterDao;
}

public Dao<Vak, Long> getVakDao() throws SQLException {
    if (vakDao == null) {
        vakDao = getDao(Vak.class);
    }
    return vakDao;
}

public Dao<Graaf, Long> getGraafDao() throws SQLException {
    if (graafDao == null) {
        graafDao = getDao(Graaf.class);
    }
    return graafDao;
}

public Dao<Vertex, Long> getVertexDao() throws SQLException {
    if (vertexDao == null) {
        vertexDao = getDao(Vertex.class);
    }
    return vertexDao;
}

public Dao<Edge, Long> 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的文件控制器:

public class Controller extends OrmLiteBaseActivity<DatabaseHelper> {

Dao<Vleugel, Long> vleugelDao;
Dao<Verdieping, Long> verdiepingDao;
Dao<NavigatiePunt, Long> navigatiePuntDao;
Dao<Lokaal, Long> lokaalDao;
Dao<Raster, Long> rasterDao;
Dao<Graaf, Long> graafDao;
Dao<Vertex, Long> vertexDao;
Dao<Edge, Long> edgeDao;
Dao<Vak, Long> 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<Vleugel, Long> qb = vleugelDao.queryBuilder();
    Where where = qb.where();
    // the name field must be equal to "foo"
    where.eq("idNaam", vleugelIDNaam);
    PreparedQuery<Vleugel> preparedQuery = qb.prepare();
    List<Vleugel> 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<NavigatiePunt, Long> qb = navigatiePuntDao.queryBuilder();
    Where where = qb.where();
    where.eq("naam", naam);
    PreparedQuery<NavigatiePunt> preparedQuery = qb.prepare();
    List<NavigatiePunt> 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<Lokaal, Long> qb = lokaalDao.queryBuilder();
    Where where = qb.where();
    where.eq("lokaalcode", lokaalcode);
    PreparedQuery<Lokaal> preparedQuery = qb.prepare();
    List<Lokaal> lokaalList = lokaalDao.query(preparedQuery);
    Log.v("GetLokaal", lokaalList.size() + "");
    if (lokaalList.size() == 1) {
        return lokaalList.get(0);
    }
    return null;
}
}

那么您对此有何建议,我应该检查什么?


问题答案:

事实证明,这是ORMLite中关于异物循环的错误,该错误已在4.22版中修复。ORMLite无法正确处理A的外场B与C的外场又回到A的情况。

http://ormlite.com/releases/

请发送给我一些直接邮件@Yanny,如果这行不通,我会相应地调整此答案。



 类似资料:
  • < code >在此输入代码我在android应用程序中有一个注册表,用户可以在其中输入他们的详细信息。我尝试将数据存储到firebase中,数据正在存储,但问题是电话号码、年龄和姓名都将被存储。如何解决这个问题?请帮帮忙! 助手类 公共类UserHelperClass { } 数据存储到Firebase代码 从其他活动获取数据 将数据传递给另一个活动 公共类注册活动扩展了应用程序兼容性活动 {

  • 我不明白为什么sequelize会生成这个专栏。 错误有: 未处理的拒绝SequelizeDatabaseError:列“PermissionID”不存在于Query.FormatError(/Home/Baptiste/IUT2/Projets3/Code/M3301/Node_Modules/Sequelize/lib/Dialects/Postgres/Query.js:366:16)的/H

  • 我使用gem在配置项中运行我的Rails6应用程序测试。在日志中,我看到正在创建具有的所有9个数据库,但它只是失败了,说这些数据库不存在。 我运行的命令是: 日志如下:

  • 日志条目:10:25 运营:08:25

  • 我正在尝试在我的设计表单上添加一个额外的字段,如下所示: 我必须允许额外的字段,所以我创建了一个新的初始值设定项devise_permitted_parameters.rb,如下所示 输出如下: "email"=? LIMIT?[["email","wtgwg@gmail.com "], ["LIMIT",1]]SQL(1.1ms)插入到"用户"("email","encrypted_passwo

  • 我正在使用多个数据库(在同一个postgresql数据库中使用不同的模式)处理Django1.9和python 3.3项目。当我第一次尝试迁移项目时,我得到了这个错误 当表未迁移时,此错误似乎会在其他项目中出现。在我的例子中,在迁移需要的应用程序之前,用开始迁移并不能解决问题。 迁移过程是否在与我的应用程序数据库相同的数据库中查找表?是绝对不同的东西吗?