Jump to content
Aliens Attack Problem
3 replies to this topic
Posted 20 October 2013 - 12:20 PM
i keep getting this error while trying to do the exercise in the first chapter
after adding a few breakpoints, i believe the problem is caused while calling the AnimateEnemy method the second time...
also some App.g.i.cs file is generated every time the application crashes.
I'm pretty clueless on to fix this, and its getting really frustrating to be stuck on the first chapter
Posted 20 October 2013 - 06:48 PM
You'll get an ArgumentOutOfRange exception with the message "'maxValue' must be greater than zero" if you pass a negative number to the random.Next() method. My guess is that it's happening in the AddEnemy() method when this is being called:
random.Next((int)playArea.ActualHeight - 100)
I bet you have a typo somewhere that's setting playArea's height to something that's less than 100 the first time AddEnemy() or AnimateEnemy() is called. That would cause a negative number to be passed into random.Next(). Copy and paste the code from the working version we published (see the book page for links). Definitely download the working program and run it, sometimes it helps to see it running so you have a working version to compare your code with. It's probably just one typo!
Other things to check: make sure the Canvas control is named playArea (and not some other control), and also make sure its height is greater than 100, which would cause a negative number to be passed into random.Next().
I hope this helps!
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
Posted 21 October 2013 - 02:00 AM
Yep, you are right, the canvas height was the problem, it was set to Auto (0) for some reason...
after changing to some random value and then setting it to auto again it worked
thank you for your help
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users