Dbflow:Model object: xxxx is not registered with a Database. Did you forge an annotation?


错误代码:



错误描述,在三星、小米手机上运行没问题,在华为手机上抛出这个异常。

网上查询没有找到原因。

官网上提示说没有在application初始化的情况会抛出这个异常,但是初始化以后还是报这个错误。

查看源码:


/**
 * @param table The table to lookup the database for.
 * @return the corresponding {@link DatabaseDefinition} for the specified model
 */
public static DatabaseDefinition getDatabaseForTable(Class<?> table) {
    DatabaseDefinition databaseDefinition = globalDatabaseHolder.getDatabaseForTable(table);
    if (databaseDefinition == null) {
        throw new InvalidDBConfiguration("Model object: " + table.getName() +
                " is not registered with a Database. " + "Did you forget an annotation?");
    }
    return databaseDefinition;
}


/**
 * Helper method used to store a database for the specified table.
 *
 * @param table              The model table
 * @param databaseDefinition The database definition
 */
public void putDatabaseForTable(Class<?> table, DatabaseDefinition databaseDefinition) {
    databaseDefinitionMap.put(table, databaseDefinition);
    databaseNameMap.put(databaseDefinition.getDatabaseName(), databaseDefinition);
    databaseClassLookupMap.put(databaseDefinition.getAssociatedDatabaseClassFile(), databaseDefinition);
}


/**
 * This is generated code. Please do not modify */
public final class DatabaseareaNew_Database extends DatabaseDefinition {
  public DatabaseareaNew_Database(DatabaseHolder holder) {
    holder.putDatabaseForTable(Njzplace.class, this);
    models.add(Njzplace.class);
    modelTableNames.put("Njzplace", Njzplace.class);
    modelAdapters.put(Njzplace.class, new Njzplace_Table(holder, this));
  }


追溯源码,并没有发现问题。


后来,突然想到


这里会不会是混淆的时候,导致的问题,因为我在debug模式中也是开启了混淆,后来发现果然是这个原因(大家可能在平时运行时没问题,但在正式签名的apk运行时会出现这个错误)。解决方法:

在 proguard-rules.pro 中添加dbflow的混淆规则

这里会不会是混淆的时候,导致的问题,因为我在debug模式中也是开启了混淆,后来发现果然是这个原因(大家可能在平时运行时没问题,但在正式签名的apk运行时会出现这个错误)。解决方法:

在 proguard-rules.pro 中添加dbflow的混淆规则


问题就此解决。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值