1.Whenever I am swiping for next picture in my app, app crashed and I don't know what's going wrong
2.This problem getting after update to Android 30 before its working fine
java.lang.NoSuchMethodError: No virtual method contains(I)Z in class Landroid/util/SparseArray; or its super classes (declaration of 'android.util.SparseArray' appears in /system/framework/framework.jar!classes2.dex)
class PostViewFragment : DialogFragment() {
private var player: SimpleExoPlayer? = null
private lateinit var mediaDataSourceFactory: DataSource.Factory
//var post: FeedNodeModel? = null
private val STORAGE_PERMISSION_CODE = 100
private var post: FeedNodeModel? = null
var currentPos = 0
var registeredFragments = SparseArray<SidecarPagerFragment>()
var isFirstLoad = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.FullScreenDialogStyle)
isCancelable = true
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
/*if (createdView != null) {
return createdView
}*/
val view = inflater.inflate(R.layout.fragment_post_view, container, false)
//post = arguments?.getSerializable("post") as FeedNodeModel?
when (post?.__typename) {
"GraphImage",
"GraphStoryImage" -> {
Picasso.get()
.load(post?.sourceUrl)
.into(view.img_post)
view.img_post.visibility = View.VISIBLE
view.playerView.visibility = View.GONE
view.viewpager.visibility = View.GONE
}
"GraphVideo",
"GraphStoryVideo" -> {
Glide.with(requireContext())
.load(post?.thumbnailUrl)
.into(object : CustomTarget<Drawable>() {
override fun onLoadCleared(p0: Drawable?) {
}
override fun onResourceReady(p0: Drawable, p1: Transition<in Drawable>?) {
initializePlayer(view.playerView,
post?.sourceUrl)
}
})
view.img_post.visibility = View.GONE
view.playerView.visibility = View.VISIBLE
view.viewpager.visibility = View.GONE
}
"GraphSidecar" -> {
val calHeight =
(resources.displayMetrics.widthPixels *
(post?.feedNodeModel?.get(0)?.dimenHeight!!)) /
post?.feedNodeModel?.get(0)?.dimenWidth!!
view.txt_pager_count.text = "1/${post?.feedNodeModel?.size}"
view.viewpager.layoutParams.height = calHeight
view.viewpager.adapter = object : FragmentPagerAdapter(childFragmentManager,
FragmentStatePagerAdapter.POSITION_NONE) {
override fun getItem(p0: Int): Fragment {
val fragment = SidecarPagerFragment.create(post?.feedNodeModel?.get(p0))
registeredFragments.put(p0, fragment)
if (isFirstLoad) {
fragment.isFirstLoad = true
isFirstLoad = false
}
return fragment
}
override fun getCount(): Int = post?.feedNodeModel?.size!!
}
view.viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
@RequiresApi(Build.VERSION_CODES.R)
override fun onPageSelected(position: Int) {
if (post?.feedNodeModel?.get(currentPos)?.__typename == "GraphVideo") {
registeredFragments[currentPos]?.onPause()
}
currentPos = position
view.txt_pager_count.text = "${currentPos+1}/${post?.feedNodeModel?.size}"
if (registeredFragments.contains(position)) {
registeredFragments[position]?.loadVideo()
}
}
})
view.viewpager.visibility = View.VISIBLE
view.img_post.visibility = View.GONE
view.playerView.visibility = View.GONE
}
}
App Crash On This Line
if (registeredFragments.contains(position)) {
registeredFragments[position]?.loadVideo()
}