@@ -106,7 +106,7 @@ class PreviewFragment : Fragment() {
106106 if (binding.buttonJoinMeeting.drawableStart == null ) {
107107 binding.buttonJoinMeeting.setDrawables(
108108 start = ContextCompat .getDrawable(
109- context !! , R .drawable.ic_live
109+ requireContext() , R .drawable.ic_live
110110 )
111111 )
112112 }
@@ -667,7 +667,16 @@ class PreviewFragment : Fragment() {
667667 enableDisableJoinNowButton()
668668
669669 updateUiBasedOnPublishParams(room.localPeer?.hmsRole?.publishParams)
670- track = MeetingTrack (room.localPeer!! , null , null )
670+
671+ // Guard against null localPeer during SDK initialization race condition.
672+ // Return early to prevent NPE crash - UI will update via other lifecycle events
673+ val localPeer = room.localPeer
674+ if (localPeer == null ) {
675+ Log .e(TAG , " LocalPeer is null in previewUpdateLiveData observer, skipping video initialization" )
676+ return @Observer
677+ }
678+
679+ track = MeetingTrack (localPeer, null , null )
671680 localTracks.forEach {
672681 when (it) {
673682 is HMSLocalAudioTrack -> {
@@ -687,8 +696,8 @@ class PreviewFragment : Fragment() {
687696
688697 binding.editTextName.doOnTextChanged { text, start, before, count ->
689698 if (text.isNullOrEmpty().not ()) {
690- val intitals = kotlin.runCatching { NameUtils .getInitials(text.toString()) }
691- binding.nameInitials.text = intitals .getOrNull().orEmpty()
699+ val initials = kotlin.runCatching { NameUtils .getInitials(text.toString()) }
700+ binding.nameInitials.text = initials .getOrNull().orEmpty()
692701 binding.noNameIv.visibility = View .GONE
693702 } else {
694703 binding.nameInitials.text = " "
0 commit comments