Reputation: 139
Am trying to call a custom dialog box but the app crashes on this line:
cd.show()
This is how I'm calling it:
val cd = CustomDialog(this, applicationContext)
cd.show()
This is the error:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState
I followed this example and it works in java but fails after converting to kotlin
Upvotes: 0
Views: 600
Reputation: 1853
You just need to pass context
when initializing CustomDialog
.
For example, try this code:
val cd = CustomDialog(this@YourActivity) //Assuming you are initializing it in Activity.
cd.show()
Upvotes: 0
Reputation: 200168
From your linked example:
@Override
protected void onCreate(Bundle savedInstanceState) {
In Kotlin, this should have become
override fun onCreate(savedInstanceState: Bundle?) {
Note the question mark, judging by your error message it's probably missing in your Kotlin code. The type Bundle
does not accept null
as a legal value (it's non-nullable) and adding a question mark to it broadens it to accept null
values.
The activity can be started with no saved instance state, such as when first starting it after installation.
Upvotes: 2