Hi Maciek ,
=20
Your test is nice and good, except it doesn't test the problem you're
running into.
=20
It sounds like you *want* to test:
=20
=20
public void ConvTest() {
ManagerResponse resp1=3D new ExtensionStateResponse();
ExtensionStateResponse resp2=3D(ExtensionStateResponse)resp1;
}
=20
A better question is... When the cast fails in your code, print out
resp1.getClass() and see if the thing you're casting really is something
you can cast from. Also, be aware that there are legitimately cases
where ManagerConnection.sendAction may not return the type you expect,
or may return a null value.
In your original snippet, I would do the following:
ManagerResponse response =3D conn.sendAction(action);
=20
if(response !=3D null)
System.out.println(response.getClass());
else
System.out.println("Response was null");
=20
// later on, cast it if response.getClass() =3D=3D
ExtensionStateResponse.class
// or if (response instanceof ExtensionStateResponse) <-- I
prefer this one better
Best,
=20
Martin Smith, Systems Developer
ma...@be...
Bureau of Economic and Business Research
University of Florida
(352) 392-0171 Ext. 221=20
=20
________________________________
From: ast...@li...
[mailto:ast...@li...] On Behalf Of
Maciek Tokarski
Sent: Friday, July 20, 2007 7:55 AM
To: ast...@li...
Subject: Re: [Asterisk-java-users] Converting ManagerResponse
toExtensionStateResponse
=09
=09
Hi,=20
=09
David Roden wrote:
>Find out what resp's type really is and work from there.
=09
maybe I do not understand the question but the type of resp
variable is ExtensionStateResponse
=09
conn.SendActrion(action) returns variable that type is
ManagerResponse.=20
=09
I've made some experiment:
function as follows:
=20
public void ConvTest() {
ManagerResponse resp1=3D new ManagerResponse();
ExtensionStateResponse resp2=3Dnew
ExtensionStateResponse();
resp2=3D(ExtensionStateResponse)resp1;
}
doesn't log classes cast problems, but it throws null-pointer
exception.=20
=09
I think it's a bug in asterisk-java
--=20
Pozdrawiam
Maciek Tokarski=20
|