当前位置: 首页 > 知识库问答 >
问题:

nosuchmethoderror:在类landroid/util/sparsearray中没有包含(I)Z的虚拟方法;

公冶京
2023-03-14

1.每当我在我的应用中刷下一张图片时,应用崩溃了,我不知道出了什么问题

noSuchMethodError:类landroid/util/sparsearray中没有包含(I)Z的虚拟方法;或其超类(“android.util.sparsearray”的声明出现在/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
        }
    }

此行应用程序崩溃

 if (registeredFragments.contains(position)) {
                        registeredFragments[position]?.loadVideo()
                    }

共有1个答案

宇文鸿振
2023-03-14

使用containskey

/** Returns true if the collection contains [key]. */
inline fun <T> SparseArray<T>.containsKey(key: Int) = indexOfKey(key) >= 0

我的领队迈克的见解

 类似资料: