针对异常
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
解决
在onCreate函数内
val navigationView = findViewById<View>(R.id.nav_view_home) as NavigationView
val headerView = navigationView.getHeaderView(0)
val tvUserName = headerView.findViewById<View>(R.id.tvUserName) as TextViewtvUserName.text=(Preference.getInstance("your text")