相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Hello there recently convert my project from java to kotlin, and faced many issues, and this is one of them

I don't know what exactly is trying to say and neither its pointing to the correct line where the error is there because at line 12 where it pointing is "import com.example.myappnotfinal.R"

Error

Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter menuInfo
        at com.example.myappnotfinal.AdaptersAndMore.PostAdapter$PostViewHolder.onCreateContextMenu(Unknown Source:12)

PostAdapter.kt

class PostAdapter     /* ShimmerFrameLayout shimmerFrameLayout; */(
    var mcontext: Context, var mUploads: List<Upload>
) : RecyclerView.Adapter<PostAdapter.PostViewHolder>() {
    private val postDiffUtil = PostDiffUtil()
    val postListDiffer = AsyncListDiffer(this, postDiffUtil)
    private var mListener: OnItemClickListener? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostViewHolder {
        val view: View = LayoutInflater.from(parent.context)
            .inflate(R.layout.post_item_container_profile, parent, false)
        return PostViewHolder(view)
    override fun onBindViewHolder(holder: PostViewHolder, position: Int) {
        val uploadCurrent = postListDiffer.currentList[position]
        val shimmer = ColorHighlightBuilder()
            .setBaseColor(Color.parseColor("#F3F3F3"))
            .setBaseAlpha(1f)
            .setHighlightColor(Color.parseColor("#E7E7E7"))
            .setHighlightAlpha(1f)
            .setDropoff(50f)
            .build()
        val shimmerDrawable = ShimmerDrawable()
        shimmerDrawable.setShimmer(shimmer)
        Glide.with(mcontext)
            .load(uploadCurrent.getmImageUrl())
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .placeholder(shimmerDrawable)
            .centerCrop()
            .fitCenter()
            .into(holder.imageView)
    override fun getItemCount(): Int {
        return mUploads.size
    fun setOnItemClickListener(listener: OnItemClickListener?) {
        mListener = listener
    fun setUploads(upload: List<Upload>) {
        mUploads = upload
    interface OnItemClickListener {
        fun onClick(view: View?)
        fun onItemClick(position: Int)
        fun onDeleteClick(position: Int)
    inner class PostViewHolder internal constructor(itemView: View) :
        RecyclerView.ViewHolder(itemView), View.OnClickListener, OnCreateContextMenuListener,
        MenuItem.OnMenuItemClickListener {
        var imageView: ShapeableImageView = itemView.findViewById(R.id.imagePost)
        override fun onClick(v: View) {
            if (mListener != null) {
                val position = adapterPosition
                if (position != RecyclerView.NO_POSITION) {
                    mListener!!.onItemClick(position)
        override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) {
            val delete = menu.add(Menu.NONE, 2, 2, "Delete")
            delete.setOnMenuItemClickListener(this)
        override fun onMenuItemClick(item: MenuItem): Boolean {
            if (mListener != null) {
                val position = adapterPosition
                if (position != RecyclerView.NO_POSITION) {
                    if (item.itemId == 2) {
                        mListener!!.onDeleteClick(position)
                        return true
            return false
        init {
            itemView.setOnClickListener(this)
            itemView.setOnCreateContextMenuListener(this)
    companion object
                thanks, it worked,  thank you, also I have some other issues can you help me with that too?  stackoverflow.com/questions/70132963/…
– Vasant Raval
                Nov 27, 2021 at 7:49
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章