Kotlin中的动态视图

I am trying to create dynamic TextView by creating an array of TextViews but getting error :

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
我的代码:
var txtViews = arrayOfNulls<TextView>(3)
    for (i in txtViews.indices) {
        txtViews = arrayOfNulls(i)
        txtViews[i]?.textSize = 24.0F
        txtViews[i]?.text = "Hello"
        txtViews[i]?.setTextColor(ContextCompat.getColor(this,
        R.color.colorAccent))
        layout.addView(txtViews[i])
    }