Praveen Kumar
07/11/2023, 6:25 AMJeff Lockhart
07/11/2023, 6:40 AMContext
reference. How is this related to multiplatform? Seems you're using a Java API that allows a platform type instead of nullable API. Most of Android's APIs have been annotated @Nullable
or @NonNull
for a while for better interop with Kotlin's nullable types. Where are you getting your Context
reference from?Praveen Kumar
07/11/2023, 6:41 AMactual typealias KMMContext = Application
herePraveen Kumar
07/11/2023, 6:41 AMJeff Lockhart
07/11/2023, 6:47 AMapplicationContext
reference you're passing here?
val pref = KMMPreference(applicationContext)
Praveen Kumar
07/11/2023, 9:09 AMactual typealias KMMContext = Application
here, this is fromJeff Lockhart
07/11/2023, 6:55 PMApplication
context reference on Android to use as indicated:
val pref = KMMPreference(applicationContext)
What are you passing here for applicationContext
?Praveen Kumar
07/12/2023, 6:26 AMJeff Lockhart
07/12/2023, 7:15 AMKMMPreference
object, passing it a KMMContext
reference. On Android, KMMContext
is typealiased to Application
(specifically android.app.Application
, which is an Android Context
). When you construct KMMPreference
, you are required to pass it a non-null Application
Context
reference. Where are you getting this reference from?
Again, this is in your code:
val pref = KMMPreference(applicationContext)
Where is applicationContext
coming from? The error you shared indicates that this reference is null, causing the crash.