Moondroid Coverflow适配器引发非法参数异常

时间:2019-04-22 09:35:27

标签: android kotlin coverflow

我正在尝试使用moondroid Coverflow库实现一个简单的Coverflow,在这里我使用位图数组列表动态设置图像,但是在运行时,它的适配器崩溃,说明一个非法参数异常。 我确定我已经按顺序完成了所有操作,但无法解决崩溃问题。 任何帮助将不胜感激。

这是我的活动课:

class SongdetailActivity : AppCompatActivity() {

    var images =ArrayList<Bitmap>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_songdetail)
        var prefs = getSharedPreferences("pref_lists", Context.MODE_PRIVATE)
        var set = prefs.getStringSet("key", null)
        val mainList = ArrayList<String>()
        mainList.addAll(set)

               try {
            val retriever = MediaMetadataRetriever()
            retriever.setDataSource(mainList.get(0))
            val art = retriever.getEmbeddedPicture()
            if (art != null) {
                var songImage = BitmapFactory.decodeByteArray(art, 0, art!!.size)
               var ob = BitmapDrawable(getResources(), songImage)
               images.add(songImage)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
        var madapter = CoverFlowAdapter(this@SongdetailActivity)
        coverflow.adapter = madapter
        madapter.setData(images)

    }
}

这是我的适配器类:

class CoverFlowAdapter(mcontext:Context) : BaseAdapter() {

    var images=ArrayList<Bitmap>()
    var context=mcontext
    override fun getCount(): Int {
        return images!!.size
    }

    override fun getItem(pos: Int): Any {
        return images!![pos]
    }

    fun setData(data: ArrayList<Bitmap>) {
        images = data
    }

    override fun getItemId(pos: Int): Long {
        return pos.toLong()
    }

    override fun getView(position: Int, convertView: View, parent: ViewGroup): View {
       var rowView = convertView
        if (rowView == null)
        {
            val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
            rowView = inflater.inflate(R.layout.item_coverflow, null)

            val viewHolder = ViewHolder()
            viewHolder.image = rowView
                    .findViewById(R.id.image)
            rowView.setTag(viewHolder)
        }

        val holder = rowView.getTag() as ViewHolder

        holder.image!!.setImageBitmap(images.get(0))

        return rowView
    }


    internal class ViewHolder {
        var text: TextView? = null
        var image: ImageView? = null
    }
}

This是我在应用程序中使用的库。

这是我在firebase crashlytics上收到的错误日志:

Fatal Exception: java.lang.IllegalArgumentException
Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
com.example.musicplayer.adapter.CoverFlowAdapter.getView (Unknown Source:2)
it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow.fillFirstTime (FeatureCoverFlow.java:570)
it.moondroid.coverflow.components.ui.containers.EndlessLoopAdapterContainer.refillInternal (EndlessLoopAdapterContainer.java:469)
it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow.refillInternal (FeatureCoverFlow.java:433)
it.moondroid.coverflow.components.ui.containers.EndlessLoopAdapterContainer.onLayout (EndlessLoopAdapterContainer.java:447)

0 个答案:

没有答案