com.reactiveandroid.internal.database.table.SQLiteType.getName() on a null object reference
Created by: hamza-am100
This is my first comment so sorry if it isn't structured the way it should.
Im using a model with a costume variable with the type org.joda.time.DateTime
, i've added a costume serializer for this type but im getting a NullPointerException. This Exception occurs on line 95 in the SQLiteUtils.java file and it's because the type of the column is null.
I think the problem has to do with line 45 and 46 in the file DatebaseInfo.java, the custom serializers are loaded after the models. Can you verify this or am i doing something wrong?
DatebaseInfo.java
public DatabaseInfo(Context context, @NonNull DatabaseConfig databaseConfig) {
loadModels(context, databaseConfig); //These two lines
loadTypeSerializers(databaseConfig); //These two lines
this.reActiveOpenHelper = new ReActiveOpenHelper(context, databaseConfig, tableInfos.values());
ReActiveLog.i(LogLevel.BASIC, "Tables info for database " + databaseConfig.databaseName + " loaded.");
}
My Serializer class:
public final class DateSerializer extends TypeSerializer<DateTime, Long> {
@Nullable
public Long serialize(@NonNull DateTime date) {
return date.getMillis();
}
@Nullable
public DateTime deserialize(@NonNull Long date) {
return new DateTime(date);
}
}
Console output:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.MyApplication.halloworld, PID: 30708
java.lang.RuntimeException: Unable to create application com.MyApplication.halloworld.config.MyApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.reactiveandroid.internal.database.table.SQLiteType.getName()' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5794)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.reactiveandroid.internal.database.table.SQLiteType.getName()' on a null object reference
at com.reactiveandroid.internal.utils.SQLiteUtils.createColumnDefinition(SQLiteUtils.java:95)
at com.reactiveandroid.internal.utils.SQLiteUtils.createTableDefinition(SQLiteUtils.java:69)
at com.reactiveandroid.internal.database.ReActiveOpenHelper.createAllTables(ReActiveOpenHelper.java:107)
at com.reactiveandroid.internal.database.ReActiveOpenHelper.onCreate(ReActiveOpenHelper.java:35)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:294)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:194)
at com.reactiveandroid.internal.database.DatabaseInfo.getWritableDatabase(DatabaseInfo.java:65)
at com.reactiveandroid.internal.database.DatabaseInfo.initDatabase(DatabaseInfo.java:55)
at com.reactiveandroid.ReActiveAndroid.init(ReActiveAndroid.java:64)
at com.MyApplication.halloworld.config.MyApplication.onCreate(MyApplication.java:37)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)