Expecting member declaration

Getting “expecting member declaration” when compile this simple android app.

package com.example.buttonone

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.view.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
}

var but1 = findViewById<Button>(R.id.but1)
var txt1 = findViewById<TextView>(R.id.actionText)

but1.setOnClickListener               <=====  Error.

}

That line is outside any function. You can’t have code at the top level of a class.

Thanks for the answer. I just copied an example:
Button Click Event in Kotlin - Android Studio Tutorial - YouTube

Yes you righjt. My fault.