L
lei
Hello,
I'm having trouble of getting ClassCastException in my code:
I'm trying to get file from server side. In my servlet service, I get
retObjct, it will pass to client side.
....
if (servicetype.equals( RCComm.GET_FILE ))
{
retObject = (Object) getFile( params );
EHEADER testob = null;
try{
testob = (EHEADER)retObject;
}
catch(Exception ex)
{//not come in here, since there's no ClassCastException
printToLogFile( "*****In service in
Servlet.java,ex.getMessage()=="+ex.getMessage());
printToLogFile( "*****In service in Servlet.java,testob=="+testob);
}
}
..... return retObject;
for above servlet code, there's no exception, which means the retObject
can be Cast as EHEADER.
But, after I pass it to client side.
In my client side, I use getObject to get the result.
ClassCastException happens here. Please check
below. I need to cast the received object to EHEADER for further
process. It seems the object
changed after server sending it and before client receiving it? Please
let me know why this happen and how can I fix it?
//===============================================================================
private static Object getObject( Hashtable params )
throws Exception
//===============================================================================
{
Object retObject = null;
try
{
.....
ObjectInputStream in = new ObjectInputStream( con.getInputStream() );
retObject = (Object) in.readObject();
EHEADER testobj = null;
try{
testobj = (EHEADER)retObject;
}
catch(Exception ex)
{
System.out.println( ex.getMessage() );//ClassCastException here,
testobj is null.
ex.printStackTrace();
}
.....
}
catch (IOException ioe)
{
ioe.printStackTrace();
throw new Exception( ioe.getMessage() );
}
I'm having trouble of getting ClassCastException in my code:
I'm trying to get file from server side. In my servlet service, I get
retObjct, it will pass to client side.
....
if (servicetype.equals( RCComm.GET_FILE ))
{
retObject = (Object) getFile( params );
EHEADER testob = null;
try{
testob = (EHEADER)retObject;
}
catch(Exception ex)
{//not come in here, since there's no ClassCastException
printToLogFile( "*****In service in
Servlet.java,ex.getMessage()=="+ex.getMessage());
printToLogFile( "*****In service in Servlet.java,testob=="+testob);
}
}
..... return retObject;
for above servlet code, there's no exception, which means the retObject
can be Cast as EHEADER.
But, after I pass it to client side.
In my client side, I use getObject to get the result.
ClassCastException happens here. Please check
below. I need to cast the received object to EHEADER for further
process. It seems the object
changed after server sending it and before client receiving it? Please
let me know why this happen and how can I fix it?
//===============================================================================
private static Object getObject( Hashtable params )
throws Exception
//===============================================================================
{
Object retObject = null;
try
{
.....
ObjectInputStream in = new ObjectInputStream( con.getInputStream() );
retObject = (Object) in.readObject();
EHEADER testobj = null;
try{
testobj = (EHEADER)retObject;
}
catch(Exception ex)
{
System.out.println( ex.getMessage() );//ClassCastException here,
testobj is null.
ex.printStackTrace();
}
.....
}
catch (IOException ioe)
{
ioe.printStackTrace();
throw new Exception( ioe.getMessage() );
}