Reputation: 10032
I am leaning Android programming in Kotlin from a video course and I have the following problem. This problem does not occur in the instructor machine; there it works without a problem.
The code
class MainActivity : AppCompatActivity() {
// lateinit var listNotes: ArrayList<Notes>
var listNotes: ArrayList<Notes>() //<=====HERE!!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Add dummy data
listNotes.add(Notes(1,"meet Profesor","asdasdasd asdads asdad asdasd asdasd asdasd"))
listNotes.add(Notes(2,"eat something","asdasddfdfdf;l;l;l;l;l;laspopopopo popo popo d asdasd"))
listNotes.add(Notes(3,"go to the movies","ann nunun nun nun ijijok koko kok okok ok nununun"))
var myNotesAdapter= myNotesAdapter(listNotes)
lvNotes.adapter= myNotesAdapter
}
//....more code
}
The problem is in the line with the ArrayList declaration. It says "getter or setter expected"
I have read some answers regarding this problem with simple variables (like putting it in the constructor etc) but what does it mean in this context with the ArrayList.
Unfortunately the instructor does not answer questions so I can't understand what is the deal here? Even stranger I can see in the video that this code does not have any problem in his machine.
Upvotes: 1
Views: 1714
Reputation: 1376
if you want to create a new instance of ArrayList<Notes>
use equal sign =
and add parentheses()
to create new instance :ArrayList<Notes>()
but if you want to declare a property with type of array list and instantiate it later , use colon :
create new instance
var listNotes = ArrayList<Notes>()
declare the property
var listNotes : ArrayList<Notes>
Upvotes: 9