rar*_*t02 4 kotlin kotlin-android-extensions android-studio-3.0
我正在 Android Studio 中将 Java 文件转换为 Kotlin,但出现此错误:
没有为参数“init”传递值
我通过添加lateinit稍微修改了代码
Java代码是:
private TextView[] dots;
private int[] layouts;
private void addBottomDots(int currentPage)
{
dots = new TextView[layouts.length];
//some lines here
}
Run Code Online (Sandbox Code Playgroud)
对应的 Kotlin 代码是
private lateinit var dots: Array<TextView>
private lateinit var layouts: IntArray
private fun addBottomDots(currentPage: Int)
{
dots = Array<TextView>(layouts.size) // error happens here
// some lines here
}
Run Code Online (Sandbox Code Playgroud)
因为我是 Kotlin 的新手,所以我不明白为什么会这样
小智 5
检查 Array 构造函数:public inline constructor(size: Int, init: (Int) -> T)- 这就是发生错误的原因。
猜你要创建ArrayList
dots = ArrayList<TextView>(layouts.size)
Run Code Online (Sandbox Code Playgroud)