Print

Print


Randall, your code snippet looks more or less correct.

	- landPortrayal's field is potatoProducers.land
	- landPortrayal's simple portrayal is a wrapper on PotatoProducer
	- potatoDistributorsPortrayal's field is potatoDistributors.land2
	- potatoDistributorsPortrayal's simple portrayal is a wrapper on PotatoDistributor

BUT

FIRST this is weird:
	         PotatoProducers potatoProducers = (PotatoProducers) state;                   
	...	 PotatoDistributors potatoDistributors = (PotatoDistributors) state;

Are PotatoProducers and PotatoDistributors both interfaces?  Is there a reason why you're casting the state (a SimState) into two different things?  

SECOND:

> The code checks out, but gives a runtime "potatoDistributors cannot be cast to potatoProducers" error. 

This is not an actual exception, and in fact it *cannot* be an exception (neither "potatoDistributors" nor "potatoProducers", as spelled, are classes).  Could you provide us with the actual error and stack trace?

Is it possible that you have put a PotatoDistributor object in your potatoProducers.land field, which is supposed to only hold PotatoProducers?  This would produce a class cast error when the portrayal tries to draw it and you try to cast it to a PotatoProducer.

Sean