Java: instanceof returning false on Eclipse CDT IncludeRefContainer class -


i have following code:

private static iproject getprojectfromactivepart(iworkbenchwindow activewindow, iselection selection) {     if (selection != null && selection instanceof istructuredselection) {         object element = ((istructuredselection) selection).getfirstelement();         if (element != null) {             if (element instanceof includerefcontainer) {                 includerefcontainer cont = (includerefcontainer) element;                 return cont.getcproject().getproject();             }         }     }     return null; } 

the statment if(element instanceof includerefcontainer) returns false, though element.getclass() returns:

class org.eclipse.cdt.internal.ui.cview.includerefcontainer

. trying cast element object includerefcontainer throws exeption:

java.lang.classcastexception: org.eclipse.cdt.internal.ui.cview.includerefcontainer cannot cast org.eclipse.cdt.internal.ui.cview.includerefcontainer 

sounds strange me. how solve this?

thanks comments got, managed solve issue: happens when class object of element loaded different class loader class loader loaded class tries perform cast. fix it, added lib in dependencies->imported packages section instead of in runtime->classpath


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -