alice-teacher Program crashes w/ index OOB exception?

Don Slater dslater at andrew.cmu.edu
Wed Nov 17 15:51:14 EST 2010


Roger,
The problem is that the "do all together" is inside the for loop… If you reverse this ordering, put the for loop inside the "do all together" then Alice executes happily (at least, she seems to)… See the attached screen shot:

In pseudo-code, essentially your student had

	for 10 times
		all the chickens in the list should make one special move

and my recommendation is that the code should actually be

	all the chickens in the list
		should make 10 special moves…

A doAllTogether is going to launch a lot of threads to handle all the disparate activities, as the system tries to keep track of separate threading for each element in a list. Therefore, the student solution was launching all of these threads times 10, and it was simply too much housekeeping.

My recommendation is launching the same basic sets of threads, and then those threads repeat the same activities 10 times…

Does this make sense?

Please let me know if you have any other questions. (This was a fun nut to crack, by the way…)

All the best,
Don Slater



-------------- next part --------------
A non-text attachment was scrubbed...
Name: ChickenHerding.png
Type: image/png
Size: 103139 bytes
Desc: not available
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20101117/e1ad28e8/attachment-0001.png 
-------------- next part --------------




On Nov 16, 2010, at 7:59 AM, Roger Wistar wrote:

> One of my students¹ programs is crashing for a very strange reason I can¹t
> identify. The student is using a list of objects and processing them with a
> ³For all XXX, every YYY together² block and using an if/else statement
> inside the block to decide what to make the object do. For some reason, when
> the else block is selected, the program crashes with the following error.
> There are exactly three items in the list, so I don¹t know why index #2
> would be OOB. I¹ve attached the A2W file and an HTML version of the source
> code.
> 
> Please help me figure out what is wrong!
> 
> Roger Wistar
> The Hotchkiss School
> 
> Error during simulation.
> 
> 
> Alice version: 2.2  05/01/2010
> 
> Throwable that caused the error:
> java.lang.ArrayIndexOutOfBoundsException: 2
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.childProlog
> ueIfNecessary(DoInOrder.java:52)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.update(DoIn
> Order.java:100)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.childUpdate
> (DoInOrder.java:58)
>    at 
> edu.cmu.cs.stage3.alice.core.response.ForEachTogether$RuntimeForEachTogether
> .childUpdate(ForEachTogether.java:74)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.update(DoIn
> Order.java:101)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoTogether$RuntimeDoTogether.update(Do
> Together.java:71)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.childUpdate
> (DoInOrder.java:58)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.update(DoIn
> Order.java:101)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.childUpdate
> (DoInOrder.java:58)
>    at 
> edu.cmu.cs.stage3.alice.core.response.DoInOrder$RuntimeDoInOrder.update(DoIn
> Order.java:101)
>    at 
> edu.cmu.cs.stage3.alice.core.response.CallToUserDefinedResponse$RuntimeCallT
> oUserDefinedResponse.update(CallToUserDefinedResponse.java:89)
>    at 
> edu.cmu.cs.stage3.alice.core.behavior.TriggerBehavior.internalSchedule(Trigg
> erBehavior.java:70)
>    at edu.cmu.cs.stage3.alice.core.Behavior.schedule(Behavior.java:233)
>    at 
> edu.cmu.cs.stage3.alice.core.Sandbox.scheduleBehaviors(Sandbox.java:70)
>    at edu.cmu.cs.stage3.alice.core.World.scheduleBehaviors(World.java:457)
>    at edu.cmu.cs.stage3.alice.core.World.schedule(World.java:499)
>    at 
> edu.cmu.cs.stage3.alice.core.clock.DefaultClock.schedule(DefaultClock.java:9
> 9)
>    at 
> edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool$7.run(AuthoringTool.java
> :692)
>    at 
> edu.cmu.cs.stage3.alice.authoringtool.util.DefaultScheduler.simulateOnce(Def
> aultScheduler.java:115)
>    at 
> edu.cmu.cs.stage3.alice.authoringtool.util.DefaultScheduler.run(DefaultSched
> uler.java:76)
>    at 
> edu.cmu.cs.stage3.scheduler.AbstractScheduler.run(AbstractScheduler.java:45)
>    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
>    at java.awt.EventQueue.dispatchEvent(EventQueue.java:633)
>    at 
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
> :296)
>    at 
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:21
> 1)
>    at 
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:20
> 5)
>    at java.awt.Dialog$1.run(Dialog.java:1045)
>    at java.awt.Dialog$3.run(Dialog.java:1097)
>    at java.security.AccessController.doPrivileged(Native Method)
>    at java.awt.Dialog.show(Dialog.java:1095)
>    at java.awt.Component.show(Component.java:1563)
>    at java.awt.Component.setVisible(Component.java:1515)
>    at java.awt.Window.setVisible(Window.java:841)
>    at java.awt.Dialog.setVisible(Dialog.java:985)
>    at 
> edu.cmu.cs.stage3.swing.DialogManager.showModalDialog(DialogManager.java:61)
>    at 
> edu.cmu.cs.stage3.swing.DialogManager.showDialog(DialogManager.java:131)
>    at 
> edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.play(AuthoringTool.java:
> 5145)
>    at 
> edu.cmu.cs.stage3.alice.authoringtool.Actions$16.actionPerformed(Actions.jav
> a:176)
>    at 
> javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
>    at 
> javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
>    at 
> javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:3
> 87)
>    at 
> javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
>    at 
> javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener
> .java:236)
>    at 
> java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
>    at java.awt.Component.processMouseEvent(Component.java:6348)
>    at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
>    at java.awt.Component.processEvent(Component.java:6113)
>    at java.awt.Container.processEvent(Container.java:2085)
>    at java.awt.Component.dispatchEventImpl(Component.java:4714)
>    at java.awt.Container.dispatchEventImpl(Container.java:2143)
>    at java.awt.Component.dispatchEvent(Component.java:4544)
>    at 
> java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
>    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
>    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
>    at java.awt.Container.dispatchEventImpl(Container.java:2129)
>    at java.awt.Window.dispatchEventImpl(Window.java:2475)
>    at java.awt.Component.dispatchEvent(Component.java:4544)
>    at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
>    at 
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
> :296)
>    at 
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:21
> 1)
>    at 
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
> :201)
>    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
>    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
>    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
> 
> 
> 
> 
> <Lists.a2w><Lists.html>_______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers



More information about the alice-teachers mailing list