Freaky ClassCastException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cristina1234
    New Member
    • Oct 2007
    • 1

    #1

    Freaky ClassCastException

    I have a constructor that takes a java.awt.Compon ent as an argument:
    public DesignContainer (Component comp,...){...}
    If I pass it a javax.media.ope ngl.GLCanvas object,it takes it,but the lines :
    comp instanceof GLCanvas -returns false
    GLCanvas canv=(GLCanvas) comp -gives ClassCastExcept ion
    (-->I cannot downcast)
    AND
    comp.getClass() .toString().equ als("class javax.media.ope ngl,GLCanvas") - returns true
    I am puzzled:
    is the object I am passing a GLCanvas or what?!! how can I verify what it is because I need to downcast...
    The interesting thing is that the program DOES draw a GLCanvas,so it should be right...(but I can't continue my work if I can't test for GLCanvas,i use it a lot in my project)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by cristina1234
    I have a constructor that takes a java.awt.Compon ent as an argument:
    public DesignContainer (Component comp,...){...}
    If I pass it a javax.media.ope ngl.GLCanvas object,it takes it,but the lines :
    comp instanceof GLCanvas -returns false
    GLCanvas canv=(GLCanvas) comp -gives ClassCastExcept ion
    (-->I cannot downcast)
    AND
    comp.getClass() .toString().equ als("class javax.media.ope ngl,GLCanvas") - returns true
    I am puzzled:
    is the object I am passing a GLCanvas or what?!! how can I verify what it is because I need to downcast...
    The interesting thing is that the program DOES draw a GLCanvas,so it should be right...(but I can't continue my work if I can't test for GLCanvas,i use it a lot in my project)
    Have a look at this

    Comment

    Working...