From: Dicheva, D. <dic...@ws...> - 2007-02-12 20:01:17
|
Hi Lars, Thanks for your prompt reply. =20 > [...] > > Collection vc =3D bn.getVariants(); > > Iterator it =3D vc.iterator(); > > while (it.hasNext()) { > > Variant var =3D (Variant) it.next(); > > Iterator si =3D var.getScope().iterator(); =20 > > if (si.hasNext()){ > > Topic param =3D (Topic)si.next(); //***Exception Here**** >=20 > > I get: JavaLangClassCastException: > > Org.TM4J.TopicMap.Memory.TopicMapImpl >=20 > Are you sure that your "Variant" is a "org.tmapi.core.Variant" and not > a "org.tm4j.topicmap.Variant"? I've the suspicion that you mix up the > classes from TM4J and TMAPI by mistake. Well, the variant is TMAPI Variant - here is the value of "var" above: org.tm4j.tmapi.core.TMAPIVariantImpl@75327fd8 The name is also an TMAPI name:=20 I divided Iterator si =3D var.getScope().iterator(); into Set s =3D var.getScope(); Iterator si =3D s.iterator(); So, now the picture is: Collection vc =3D bn.getVariants(); Iterator it =3D vc.iterator(); while (it.hasNext()) { Variant var =3D (Variant) it.next(); Set s =3D var.getScope(); Iterator si =3D s.iterator(); =20 if (si.hasNext()){ Topic param =3D (Topic)si.next(); //***Exception Here**** =20 and just before the exception I have: var: org.tm4j.tmapi.core.TMAPIVariantImpl@75327fd8 but in the Set s: HashMap -> Table -> HashMap$Entry -> key [4] =3D org.tm4j.topicmap.memory.TopicImpl@d00f8c41 and the imports are: import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.tmapi.core.Locator; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicName; import org.tmapi.core.Variant; import org.tmapi.index.core.TopicNamesIndex; So, I am not using TM4J directly, only TMAPI. Which means that the TMAPI getScope() applied on the TMAPI variant var returns an unmodifiable set of TM4J topics and that is why I am getting the cast exception. > If you need to work with TM4J interfaces *and* TMAPI interfaces, the > class "org.tm4j.tmapi.helpers.Wrapper" may help you to 'wrap' and > 'unwrap' objects into both directions. I don't really want to work with both interfaces, so I only use the TMAPI interface. Any further idea?=20 Thanks, Darina >=20 > Best regards, > Lars > --=20 > http://www.semagia.com > http://www.topicgarden.com/mailinglist/ German Topic Maps mailinglist >=20 >=20 |