Hi I have a problem with following excersise:
https://www.codecademy.com/courses/learn-the-basics-of-android/informationals/simple-calculator-project
I am at step 7 trying to access UI elements by utilizing the findViewById()
function. But when trying to use EditText Class i get following problems:
-Function invocation ‘EditText(…)’ expected
-None of the following functions can be called with the arguments supplied…
-Expecting an element
So i checked my xml code and do not know what i have done wrong or where to look at.
According to my definition (literally 1-1 as described by codecademy) xml code is:
<EditText
android:id="@+id/number1"
and my Java code:
package com.codeacademy.simplecalculator
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.EditText
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
EditText test = findViewById(R.id.number1); // what is wrong here!?
}
}
could anyone explain me what i have done wrong or show me where I should look at? according to the video the code posted there is different and when i do the 1 by 1 typing it all turns red…
Thank you in advance and sorry if I am too much of a nab, I literrally started learning programming a short while ago.