androidkotlinnullpointerexceptionparcelableandroid-13

'boolean java.lang.Class.isInterface()' on a null object reference


I'm facing this crash on Android 13 at following code.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference

Code:

val temp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) 
    bundle.getParcelable(ARG_TAG, Tab::class.java)
else 
    bundle.getParcelable(ARG_TAG)

DataClass (Tab) is as follow:

@Keep
@Parcelize
data class Tab(
    val data: List<String>? = null,
    val icon: String? = null,
    val provider: String? = null,
    val subtype: String? = null,
    val title: String,
    val items: Int = 0
) : Parcelable

Solution

  • I've found solution, by using recommended approach for Android-13 BundleCompat

    val temp = BundleCompat.getParcelable(bundle, ARG_TAG, Tab::class.java)