简体   繁体   English

如何在 Kotlin 中声明变量? 我收到“未解决的参考”

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

I am getting errors on the lines compiling message_text .我在编译message_text的行中遇到错误。

在此处输入图片说明

You never "closed" lambda for the start_button click listener.您永远不会为start_button单击侦听器“关闭”lambda。 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.您必须声明变量,并且在使用它们之前应该通过 id 标识视图,如下所示。

    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");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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