17

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

1 Answer 1

15

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

val temp = BundleCompat.getParcelable(bundle, ARG_TAG, Tab::class.java)
Sign up to request clarification or add additional context in comments.

7 Comments

How about for Activity Intent? This issue seems plague the Android 13 so bad that it is also only showing in release build.
the check is already done inside. BuildCompat.isAtLeastU()
Thank you. I had the same problem and your solution fixed it for me too. I've been a professional developer for nearly 30 years and I've never come across a platform as fiddly to work with as Android!
for anyone wondering what is wrong with api 33 implementation here is the description by google dev issuetracker.google.com/issues/240585930#comment6
Note also IntentCompat.getParcelableExtra
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.