kotlin 踩坑记二

才没写几行代码,kotlin又来惹事了。问题如下:

kotlin.NotImplementedError: An operation is not implemented: not implemented

继承类后,自动导入方法,直接运行后报错。

override fun initView(view: View?, savedInstanceState: Bundle?) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

不知道你们有没有注意到方法里面第一行代码-- TODO ,可能在Android里面加个TODO并不会影响程序运行,可是在Kotlin里面就不一样啦,如果你在某个函数的第一行添加TODO的话,那么很抱歉,它不会跳过,然后运行下一行代码。那如果真要添加TODO的话,那就只能在函数的最后一行添加了。


知道原理后就好办了,我们只需要把TODO("not implemented") 这句话去掉就可以啦!

参考:https://stackoverflow.com/questions/50503780/kotlin-notimplementederror-an-operation-is-not-implemented-not-implemented-err

猜你喜欢

转载自blog.csdn.net/kdsde/article/details/82528177