我正在尝试使用 Kotlin 构建我的第一个 android 应用程序,但我陷入了一个非常简单的情况。我正在使用 Kotlin android 扩展,我得到一个空指针异常。
<TextView
android:id="@+id/tvGoToRegisterFrag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn_sign_in"
android:text="@string/haven_t_registered_yet"
android:paddingTop="10dp"
android:textColor="@color/colorAccent"
android:layout_centerHorizontal="true"/>
有了这个我用
tvGoToRegisterFrag.setOnClickListener {
goToRegister()
}
我知道我可以使用
tvGoToRegisterFrag?.setOnClickListener {
goToRegister()
}
为了摆脱崩溃,但我仍然不确定为什么该对象为空并且单击时不执行任何操作。如果这改变了任何东西,所有这些都在一个片段中完成。