While executing the code below:

while (response != null) {

            try {

            MsgResponse msgResponse = (MsgResponse)response;

           

            XQMessage respMsg = msgResponse.getResponseMessage();

           

            XQPart part = respMsg.getPart(0);            

           

            if(part == null){

            throw new Exception("No part");

            }

            }

            catch(Exception e){

            result.addError(this,e);

            }

            finally

            {

            prevResponse = response;

                response = response.getNextResponse(60000); // To get the next response

            }

        }

MsgResponse msgResponse = (MsgResponse)response; <-- throws a "java.lang.ClassCastException".

Can anyone tell me why this is happening?