ReadObject - NewInstance of unknown Object's
I have a Client/Server connection over sockets.
The server returns different types of Objects. I run the readObject method then, how can I instantiate the received class object ?
Seems to work fine when the Object is a String class but I receive the following error for java.io.file class:
java.lang.InstantiationException: java.io.File
at java.lang.Class.newInstance0(Class.java:293)
at java.lang.Class.newInstance(Class.java:261)
Code Example:
try{
Object o = connectionRef.readObject();
try{
Class c = Class.forName(new ro.util.string.GetWord(o.getClass().toString(),1).toString() );
Object co = c.newInstance();
System.err.println("Built Instance of Class=" + co.getClass().toString() );
}catch ( Exception e){
e.printStackTrace();
System.exit(1);
}
}catch ( Exception e ){
e.printStackTrace();
}
Message was edited by:
RobOsborne

