-2

I want to create an instance , put it on a container and send it.

TransferContainer container = null;
    ...
  Class aClass = container.getByteCode();
    o = aClass.newInstance();
    ....// Some code
    ...
    container.setInstance(o);
    ObjectOutputStream out = new ObjectOutputStream(_s.getOutputStream());
    out.writeObject(container);

I get this error

java.io.NotSerializableException If I don't add the the instance o in the container I can send it without any problem.

user567
  • 3,712
  • 9
  • 47
  • 80

1 Answers1

0

The reason for this exception is that aClass or some instance field of aClass doesn't implement Serializable.

user207421
  • 305,947
  • 44
  • 307
  • 483
Vipin
  • 4,851
  • 3
  • 35
  • 65
  • aClass can be any given class by the user , Class aClass = container.getByteCode(); – user567 Jul 11 '14 at 21:36
  • @user567 fine. But if u want to serialize it , its all instance fields must implement serializable or make them transient if they are not required otherwise this is expected error. – Vipin Jul 11 '14 at 21:44
  • @user567 Then your design is wrong. You can only allow classes that are Serializable. – user207421 Jul 11 '14 at 21:44
  • If it is some kind of API you are publishing then properly document it also so that user are aware of this fact before sending any class. – Vipin Jul 11 '14 at 21:45