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.
For the exception, wrap your code in
The other messages are warnings which won’t stop your program from compiling. They refer to needing a parameter on parametrised types to adhere to new specifications (as of Java 1.5). So, if you want to store integers in a Vector, use
Vector<Integer>. This changes the methods to requiringIntegersinstead of the genericObjectyou’d normally get and increases type-safeness.