By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,333 Members | 696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,333 IT Pros & Developers. It's quick & easy.

Freaky ClassCastException

P: 1
I have a constructor that takes a java.awt.Component as an argument:
public DesignContainer(Component comp,...){...}
If I pass it a javax.media.opengl.GLCanvas object,it takes it,but the lines :
comp instanceof GLCanvas -returns false
GLCanvas canv=(GLCanvas)comp -gives ClassCastException
(-->I cannot downcast)
AND
comp.getClass().toString().equals("class javax.media.opengl,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)
Oct 4 '07 #1
Share this Question
Share on Google+
1 Reply

10K+
P: 13,262
I have a constructor that takes a java.awt.Component as an argument:
public DesignContainer(Component comp,...){...}
If I pass it a javax.media.opengl.GLCanvas object,it takes it,but the lines :
comp instanceof GLCanvas -returns false
GLCanvas canv=(GLCanvas)comp -gives ClassCastException
(-->I cannot downcast)
AND
comp.getClass().toString().equals("class javax.media.opengl,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
Oct 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.