简体   繁体   中英

Why is there an error? kotlin (unresolved reference)

I have question

android studio kotlin

unresolved reference: .append

What is the solution?

thank you

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {

    var a: String = ""
    var list = mutableListOf<String>()
    var b: Long = 0L
    var c: Long = 1L

    var d: Double = 1.0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        num1.setOnClickListener {
            all_result.setText(all_result.getText().append("1"))
            a = all_result.getText().toString()        
}        
}    
}

It seems that all_result in your case is EditText . In this case getText() returns Editable , but not String or StringBuilder . So, you should write something like this: "${all_result.getText().toString()}1" to concatenate existing string in EditText with '1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM