Closed DeadNumbers closed 4 years ago
Because you have a bug in your slice code. You create the slices with make([]*ui.Entry, 20)
, which creates a slice with 20 elements, all nil pointers. You then create the entries with itemsEnt = append(itemsEnt, ui.NewEntry())
, which adds another item to the end of the slice, growing it from having length 20 to having length 21, with 20 nil pointers and 1 non-nil pointer. You wanted to say itemsEnt[i] = ui.NewEntry()
instead. (Alternatively, you can use make([]*ui.Entry, 0, 20)
, which makes a slice that has length 0 but with space for 20 pointers pre-allocated. Then, your append()
calls will work as you expect.)
Oh, I'm stupid and inattentive. @andlabs Thanks!