gpt4 book ai didi

android - NoSuchMethodError: 类 Landroid/util/SparseArray 中没有虚方法包含 (I)Z;

转载 作者:行者123 更新时间:2023-12-02 12:44:40 27 4
gpt4 key购买 nike

1.每当我在我的应用程序中滑动查看下一张图片时,应用程序就会崩溃,我不知道出了什么问题

2.这个问题在更新到 Android 30 之后才正常工作

java.lang.NoSuchMethodError: 类 Landroid/util/SparseArray 中没有虚方法包含 (I)Z;或其父类(super class)('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()
}

最佳答案

使用containsKey

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

我的团队领导的见解 Mike

关于android - NoSuchMethodError: 类 Landroid/util/SparseArray 中没有虚方法包含 (I)Z;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63508558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com