PDA

View Full Version : Why can't i cast header to a custom header?



edfimasa
25 Nov 2008, 7:18 AM
Hi.

I'm trying to cast Header to a Custom Header -> MyHeader class, but it doesn't let me.

Even if the custom class is as follows:

public class MyHeader extends Header{
}

if i do the following MyHeader mh = (MyHeader) contentpane.getHeader();

It gives me a casting error.

What can i do? I need a class header that implements SourcesMouseEvents,and the only way i know how, is to extend header and implement SourcesMouseEvents.

Any idea?

Cheers.

fother
25 Nov 2008, 7:26 AM
It gives me a casting error.


please post the error.

edfimasa
25 Nov 2008, 7:37 AM
[ERROR] Uncaught exception escaped
java.lang.ClassCastException: com.extjs.gxt.ui.client.widget.Header cannot be cast to com.myapp.client.MyHeader

the code

MyHeader mh = (MyHeader) contentpanel.getHeader();

The only difference from Header to MyHeader, is that the ladder implements the
SourcesMouseEvents.

fother
25 Nov 2008, 9:07 AM
create MyContentPanel in contrutor set header = MyHeader and use MyContentPanel

edfimasa
25 Nov 2008, 9:52 AM
Hi thanks for your reply.

I can't test right now your solution.

But using inside MyContentPanel class super.head = myheader supposly will give the same cast error. Because you'r doing a cast from MyHeader to Header.

Before your reply i found a hardy solution, that was to build a MyContentPanel from scratch, and several other needed components.

Thanks.

kolli
25 Nov 2008, 1:26 PM
well i dont think this question comes anywhere near gxt.
It is just that we cannot store an object reference of a parent class in a reference variable of subClass type. Try looking for inheritance.

edfimasa
26 Nov 2008, 2:21 AM
Your're right Koli. I forgot i can't downcast from super class to subclass. But i swear i did this in other languages other than java.

I posted this because at the time, i tought it could be some problem with GXT, I apologize.

Cheers.

kolli
26 Nov 2008, 5:34 AM
thats ok no problem