简体   繁体   中英

How to declare variables in Kotlin? I'm getting "Unresolved Reference"

I am getting errors on the lines compiling message_text .

在此处输入图片说明

You never "closed" lambda for the start_button click listener. Add a closing curly brace } :

    ...
    text_id.text = "my text"
} // <- this one's missing

you have to declare the variables and you should identify the view by id before using them as below.

    TextView message_text;

    Override fun onCreate(savedInstanceState: Bundle?){

       Super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main);

        message_text = (TextView) findViewById(R.id.message_text);
        message_text.setText("abc");
    }

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