我问了一个关于将cometchat集成到我的应用程序中的问题。我没有得到任何答复,但我会继续问安蒂,我解决了我的问题,因为我是非常新的科林。按照cometchat网站关于如何注册用户的指示,我在主要活动中添加了以下代码
val authKey = "AUTH_KEY" // Replace with your App Auth Key
val user = User()
user.getUid() = FirebaseAuth.getInstance().currentUser!!.uid // Replace with the UID for the user to be created
user.getfullname() = full_name.toString() // Replace with the name of the user
CometChat.createUser(user, authKey, object : CometChat.CallbackListener<com.cometchat.pro.models.User>() {
override fun onSuccess(user: User) {
Log.d("createUser", user.toString()
}
override fun onError(e: CometChatException) {
Log.e("createUser", e.message)
}
})不幸的是,user.getUid的下划线是红色的“变量预期”。我不知道那是什么意思。这是我的用户对象
package Model
class User {
private var stOforigin: String = ""
private var fullname:String =""
private var bio:String =""
private var image:String =""
private var uid:String =""
private var gender:String =""
private var email:String =""
constructor()
constructor(fullname:String, bio:String, image:String, uid:String, gender:String , sos:String,
email:String){
this.fullname = fullname
this.bio = bio
this.image= image
this.uid = uid
this.stOforigin = sos
this.gender =gender
this.email = email
}
fun getfullname(s: String): String{
return fullname
}
fun setfullname(fullname: String){
this.fullname= fullname
}
fun getBio(): String{
return bio
}
fun setBio(bio: String){
this.bio= bio
}
fun getImage(): String{
return image
}
fun setImage(image: String){
this.image= image
}
fun getUid(uid: Any?): String{
return this.uid
}
fun setUid(uid: String){
this.uid= uid
}
fun getGender(): String{
return gender
}
fun setGender(gender: String){
this.gender= gender
}
fun getstOforigin(): String{
return stOforigin
}
fun setstOforigin(stOforigin: String){
this.stOforigin= stOforigin
}
fun getEmail(): String{
return email
}
fun setEmail(email: String){
this.email = email
}}
发布于 2022-05-07 22:28:32
不能为函数调用分配值。换句话说,无论foo() = 123做什么,foo()都是无效的语法。在您的情况下,与其调用getter样式函数(get...()),不如调用setter样式函数(set...()),将所需的值作为参数传递。
取代:
user.getUid() = FirebaseAuth.getInstance().currentUser!!.uid // Replace with the UID for the user to be created
user.getfullname() = full_name.toString() // Replace with the name of the user通过以下方式:
user.setUid(FirebaseAuth.getInstance().currentUser!!.uid) // Replace with the UID for the user to be created
user.setfullname(full_name.toString()) // Replace with the name of the user你可能想把这一切放在一边,先把注意力放在学习Kotlin上。如果有帮助的话,这是我关于科特林的一本免费书。。
https://stackoverflow.com/questions/72156742
复制相似问题