‘boolean java.lang.Class.isInterface()’ 在一个空对象引用上。

huangapple go评论74阅读模式
英文:

'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? = null,
val icon: String? = null,
val provider: String? = null,
val subtype: String? = null,
val title: String,
val items: Int = 0
) : Parcelable

英文:

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

得分: 1

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

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

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

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

huangapple
  • 本文由 发表于 2023年7月5日 00:04:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614322.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定