Casting Problem
Closed this issue · 2 comments
Hello
I would appreciate it if you could assist me in solving the below mention problem.
In the below code, the line "else if (isSubClassesOfvisisted(visited, (OWLClass) superClass.getSuperClass())) {", shows the exception as
output:
owl:Thing
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl cannot be cast to org.semanticweb.owlapi.model.OWLClass
How to resolve this problem?
for (OWLSubClassOfAxiom superClass : supClassList) {
// System.out.println(superClass.getSuperClass());
if (visited.contains(superClass.getSuperClass())) {
visited.add(subClass);
value = true;
} else if (isSubClassesOfvisisted(visited, (OWLClass) superClass.getSuperClass())) {
value = true;
visited.add(subClass);
} else {
value = false;
}
}
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl cannot be cast to org.semanticweb.owlapi.model.OWLClass
Hi,
you're trying to cast an OWLClassExpression to OWLClass (in this case it's an existential restriction, i.e., SomeValuesFrom)
You should check if the object is anonymous or not before casting it.
Thank you very much for your explanation. Got it :)