0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Android App crashed immediately when open a dailog using BaseAdapter

Last updated at Posted at 2023-06-02

元々はJavaで実装しましたがIntellijを利用してkotlinに変換しました。ところがAlertDialogを開く瞬間APPがcrashしました。このAlertDialogはsetAdapter()を利用して自分で実装したListAdapterを表示する

val builder = AlertDialog.Builder(this)
builder.setAdapter(playingAdapter) { dialog, item ->
                Log.d("MyApp", item.toString())
            }
class CustomListAdapter    //public constructor
    (//context
    private val context: Context, //data source of the list adapter
    private val items: List<Music>
) : BaseAdapter() {
    override fun getView(
        position: Int,
        convertView: View,
        parent: ViewGroup
    ): View {}

原因はconvertView: Viewはダメです。convertViewはnullになる可能性があるのでconvertView: View?すべきです。

 override fun getView(
        position: Int,
        convertView: View?,
        parent: ViewGroup
    ): View
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?