title: Unresolved Reference using Kotlin for android
body: <p>I am getting Unresolved Reference when compiling </p>
  
  <p>Error:(42, 26) Unresolved reference: r1
  Error:(42, 36) Unresolved reference: ds</p>
  
  <p>in the onClick method variables r1, and ds are shown to be in errors.
  in kotlin all varibales are final. so how come it is not accepting it. 
  please advice following is the script</p>
  
  <pre><code>class MainActivity : AppCompatActivity(), View.OnClickListener {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          val b1: Button = findViewById(R.id.add)
  
          val a1: EditText = findViewById(R.id.opr1)
          val a2: EditText = findViewById(R.id.opr2)
  
          val d1: Int = (a1.getText().toString().toInt())
          val d2: Int = (a2.getText().toString().toInt())
  
        var r1: TextView = findViewById(R.id.res)
          var ds :Int =d1+d2
  
  
      }
  
      override fun onClick(v: View?) {
  
          when (v?.id) {
  
              R.id.add -&gt;  r1.text= (ds).toString()
  
          }
      }
  }
  </code></pre>