即使我将变量分配为 var,我也会得到 "Val cannot be reasigned error"?

I get a "Val cannot be reasigned error" even though I assigned the variable as var?

我正在尝试向应用程序添加“复制到剪贴板”功能。我在图像按钮上添加了一个 setOnClickListener 用于复制并编写了下面的代码。我仍然在“clipBoard.primaryClip = clip”行

上收到“无法重新分配 val”错误
            var clipBoard: ClipboardManager = getActivity()?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            val StrEdtFirtname = etNoteDesc.text.toString()
            val clip = ClipData.newPlainText("Copied text",StrEdtFirtname)
            clipBoard.primaryClip = clip
            Toast.makeText(requireContext(), "Copied text", Toast.LENGTH_SHORT).show()
        }

尝试使用以下代码。

var clipBoard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
     val StrEdtFirtname = etNoteDesc.text.toString()
    val clip = ClipData.newPlainText("Copied text",StrEdtFirtname)
    clipBoard.apply {
        setPrimaryClip(clip)
    }