I get the following error when using the following custom application class, the class only initialises a Room Database instance to be used throughout the application:
class MyApplication : Application() {
var appDB: AppDatabase = Room.databaseBuilder(
applicationContext, AppDatabase::class.java, "Sensor App Database"
).build()
}
java.lang.RuntimeException: Unable to instantiate application com.example.test.MyApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
The application builds normally when I remove the custom application class from the android manifest:
<application
android:name=".MyApplication"