简体   繁体   English

Android Room迁移-java.lang.IllegalArgumentException:指定为非null的参数为null

[英]Android Room Migration - java.lang.IllegalArgumentException: Parameter specified as non-null is null

I am trying to add a column to an existing table in the database. 我正在尝试向数据库中的现有表添加一列。 The column is type ArrayList<Date> I wrote a migration step, increased database version number, and added the migration. 该列的类型为ArrayList<Date>我编写了一个迁移步骤,增加了数据库版本号,并添加了迁移。 When I run the migration (run the app), I get the error: 当我运行迁移(运行应用程序)时,出现错误:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter value java.lang.IllegalArgumentException:指定为非null的参数为null:方法kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull,参数值

when attempting to read data from that table. 尝试从该表读取数据时。

I have tried following the steps here: https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929 我尝试按照以下步骤操作: https : //medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929

I have also tested with other data types, and it has migrated successfully. 我还对其他数据类型进行了测试,并且已成功迁移。 Seems like the issue is adding Lists or ArrayList s. 似乎问题出在添加List或ArrayList

val MIGRATION_2_3 = object : Migration(2, 3) {
    override fun migrate(database: SupportSQLiteDatabase) {
        database.execSQL(
            "ALTER TABLE product ADD COLUMN ingredients TEXT"
        )
    }
}

You're altering a table without setting a default value. 您正在更改表而未设置默认值。 Therefore the default is null for all rows already present within the table. 因此,对于表中已经存在的所有行,默认值为null。 Since you require the Kotlin property to be non-null, you receive the IllegalArgumentException . 由于您要求Kotlin属性为非null,因此会收到IllegalArgumentException

To resolve the issue, you'd have to alter the table to contain a default value for ingredients and declare it non-null as well. 要解决此问题,您必须更改表以包含ingredients的默认值,并将其声明为非null。

val MIGRATION_2_3 = object : Migration(2, 3) {
    override fun migrate(database: SupportSQLiteDatabase) {
        database.execSQL(
            "ALTER TABLE product ADD COLUMN ingredients TEXT NOT NULL DEFAULT ''"
        )
    }
}

Alternatively you could make the ingredients Kotlin property nullable. 或者,您可以使ingredients Kotlin属性为空。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:指定为非空的参数是 null:- android,应用程序启动但立即崩溃 - java.lang.IllegalArgumentException: Parameter specified as non-null is null: - android, app starting but crashing straight away java.lang.IllegalArgumentException:指定为非空的参数是 Java 代码中的 null 错误 - java.lang.IllegalArgumentException: Parameter specified as non-null is null error in Java code 错误:java.lang.IllegalArgumentException:指定为非null的参数为空Firebase事务Kotlin - Error: java.lang.IllegalArgumentException: Parameter specified as non-null is null firebase transaction kotlin 由java.lang.IllegalArgumentException引起的指定为非null的参数为null - Parameter specified as non-null is null caused by java.lang.IllegalArgumentException java.lang.IllegalArgumentException:对于 Kotlin 和 WebView,指定为非 null 的参数为 null - java.lang.IllegalArgumentException: Parameter specified as non-null is null for Kotlin and WebView java.lang.IllegalArgumentException:将JSON解析为kotlin Data类时,指定为non-null的参数为null - java.lang.IllegalArgumentException: Parameter specified as non-null is null while parsing JSON to kotlin Data class java.lang.IllegalArgumentException:指定为非空的参数是 null:方法 kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull - java.lang.IllegalArgumentException : Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull - java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull IllegalArgumentException:指定为非空的参数为空 - IllegalArgumentException: Parameter specified as non-null is null Kotlin:java.lang.NullPointerException:指定为非空的参数在 Java 2 Kotlin 迁移后为空 - Kotlin: java.lang.NullPointerException: Parameter specified as non-null is null after Java 2 Kotlin migration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM