2

我在 ORMLite Sourceforge 错误跟踪器上将此作为错误提出,但我没有看到任何更新。我没有看到任何流程文档说我是否需要做任何事情才能将其传递给 Gray?

看到测试 v4.47(旧 ORMLite 版本的行为更糟​​糕,因为配置文件生成失败得更早)。

我的 @DatabaseTable 类都包含一些 Android 导入,例如

import android.content.Context;

我的大多数类都扩展了一个抽象超类,例如

@DatabaseTable(tableName = SongMessage.TABLE_NAME)
public class SongMessage extends AbstractMessage {

但是,我的一些类扩展了一个共享的抽象超类,例如

@DatabaseTable(tableName = PhotoMessage.TABLE_NAME)
public class PhotoMessage extends SingleImageMessage implements <snip> {

SingleImageMes​​sage 扩展了相同的通用 AbstractMessage:

public abstract class SingleImageMessage extends AbstractMessage {

运行我的 OrmLiteConfigUtil 对我的直接子类运行良好,但对扩展中间抽象类的子类不起作用:

...
Wrote config for class com.mypackage.TextMessage
Skipping class com.mypackage.PhotoMessage because we got an error finding its definition: android/content/Context
Wrote config for class com.mypackage.SongMessage
...
4

2 回答 2

1

抱歉这么晚才回复。ORMLite 最近有点被换掉了。

运行我的 OrmLiteConfigUtil 对我的直接子类运行良好,但对扩展中间抽象类的子类不起作用:

这个问题显然是因为Context导入。不幸的是,OrmLiteConfigUtil 正在本地运行,并且无法访问该类,该类仅由 Google 导出为存根。

我可以做的一件事是仅在无法调查超类时捕获并记录错误。所以子类将被正确输出。那行得通吗?

于 2013-12-18T20:47:14.160 回答
0

我可能需要查看更多您的抽象类定义。该错误可能来自 DatabaseFieldConfig.fromField 调用。错误消息表明它正在尝试查找 android.content.Context 的数据库类型定义。您的抽象类中是否声明了该类型的字段?这是产生您所看到的错误消息的代码。

    private static void writeConfigForTable(BufferedWriter writer, Class<?> clazz) throws SQLException, IOException {
    String tableName = DatabaseTableConfig.extractTableName(clazz);
    List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    // walk up the classes finding the fields
    try {
        for (Class<?> working = clazz; working != null; working = working.getSuperclass()) {
            for (Field field : working.getDeclaredFields()) {
                DatabaseFieldConfig fieldConfig = DatabaseFieldConfig.fromField(databaseType, tableName, field);
                if (fieldConfig != null) {
                    fieldConfigs.add(fieldConfig);
                }
            }
        }
    } catch (Error e) {
        System.err.println("Skipping " + clazz + " because we got an error finding its definition: "
                + e.getMessage());
        return;
    }
    if (fieldConfigs.isEmpty()) {
        System.out.println("Skipping " + clazz + " because no annotated fields found");
        return;
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    DatabaseTableConfig<?> tableConfig = new DatabaseTableConfig(clazz, tableName, fieldConfigs);
    DatabaseTableConfigLoader.write(writer, tableConfig);
    writer.append("#################################");
    writer.newLine();
    System.out.println("Wrote config for " + clazz);
}
于 2013-11-07T16:59:50.713 回答