如何解决“未处理的异常类型ClassNotFoundException”和“向量是原始类型”错误?
在 servlet 方面,我试图接收从小程序发送的向量。代码就像
InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
Vector v = (Vector) inputFromApplet.readObject();
但是编译器指定以下代码是错误的。
Vector v = (Vector) inputFromApplet.readObject();
错误信息是
该行有多个标记
- 未处理的异常类型 ClassNotFoundException
- Vector 是原始类型。对泛型类型 Vector 的引用 应该参数化
- Vector 是原始类型。对泛型类型 Vector 的引用 应该参数化
我的代码有什么问题吗?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于例外情况,请将您的代码包装在
其他消息中是警告,不会阻止您的程序编译。他们指的是需要参数化类型上的参数来遵守新规范(从 Java 1.5 开始)。因此,如果您想在 Vector 中存储整数,请使用
Vector
。这会将方法更改为需要Integers
而不是您通常获得的通用Object
,并提高类型安全性。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 requiringIntegers
instead of the genericObject
you'd normally get and increases type-safeness.您想要为向量指定数据类型——例如,
字符串可能不是您的应用程序的最佳选择。
You want to specify a datatype for vector -- e.g.
String might not be the best choice for your application, however.