In servlet side, I am trying to receive an vector sent from the applet. The code is like

InputStream in = request.getInputStream();
    ObjectInputStream inputFromApplet = new ObjectInputStream(in);
    Vector v = (Vector)inputFromApplet.readObject();

But the compiler specifies that the following one is wrong.

Vector v = (Vector)inputFromApplet.readObject();

The error message is

Multiple markers at this line - Unhandled exception type ClassNotFoundException - Vector is a raw type. References to generic type Vector should be parameterized - Vector is a raw type. References to generic type Vector should be parameterized

What's wrong with my code? Thanks.

1. readObject can throw Exceptions (see the JavaDoc for details) so you have to use try/catch to handle them.
2. In Java 1.5 collections like Vector were enhanced to allow specification of what kind of Objects they contain (previously they just contained Objects, which had to be cast at runtime to (hopefully) the appropriate class. Since 1.5 you can say things like
Vector<String> v = new Vector<String>(); // this vector always and only holds Strings
So now Vectors without such a specification are called "raw types", and you are strongly recommended to update them to the improved version. If the vector really does hold absolutely any kind of Object, you can use Vector<Object>.
Look up "Java generics" for more details.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.