0

I have problem many time understanding the errors i get in the squeak program, and unable to fix and debug it. like in this case:

I wrote the following code is smalltalk language in squeak:

initilize

super initialize.
path := OrderedCollection new.

-

drawOn: aCanvas
| colors |
colors := Color wheel: 10.
colors withIndexDo:[:c :i | 
aCanvas fillOval: (self bounds insetBy: self width/25*i+1 )
color: c
].

-

handlesMouseDown: evt
^true.

-

mouseDown: evt

self position: self position + (10@0).

-

startAnimation

    path reset.
    0 to: 9 do: [:i | path add: self position +(0@(10*i))].
    path := path, path reverse.
    self startStepping.

-

step

path size > 0 ifTrue: [self position: path removeFirst].

and this is the code I wrote in the workspace:

myMorph := TestMorph new openInWorld.

but I am getting and error that I wrote up, something about problem with "size" in "step" method can someone see the problem?

Yuval Levy
  • 2,397
  • 10
  • 44
  • 73
  • 1
    The error means that your `path` variable in `#step` method is `nil`. I cannot see problem in your code though. Either you do something more, you we need someone keener you spot the problem :) – Uko May 22 '14 at 13:41
  • @Uko is right, I also fail to spot an error here. – Tobias May 22 '14 at 14:13

1 Answers1

5

When you get an error message about UndefinedObject it often means that some variable was not initialized correctly, it has the value nil.

The error is that you misspelled initialize

You wrote initilize instead. This method is not called when creating your object and thus the path instance variable is let undefined (nil).

codefrau
  • 4,583
  • 17
  • 17
aka.nice
  • 9,100
  • 1
  • 28
  • 40