gpt4 book ai didi

java - 如何解决 "Unhandled exception type ClassNotFoundException"和 "Vector is a raw type"错误?

转载 作者:行者123 更新时间:2023-11-30 07:33:10 25 4
gpt4 key购买 nike

在 servlet 端,我试图接收从 applet 发送的 vector 。代码是这样的

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

但是编译器指出下面这个是错误的。

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

错误信息是

Multiple markers at this line

  • Unhandled exception type ClassNotFoundException
  • Vector is a raw type. References to generic type Vectorshould be parameterized
  • Vector is a raw type. References to generic type Vectorshould be parameterized

我的代码有什么问题?谢谢。

最佳答案

对于异常(exception)情况,请将您的代码包装在

try {
<your code here>
} catch (ClassNotFoundException e) {
<code that happens when class can't be found>
}

其他消息是不会阻止您的程序编译的警告。他们指的是需要参数化类型的参数以遵守新规范(从 Java 1.5 开始)。所以,如果你想在 Vector 中存储整数,使用 Vector<Integer> .这将方法更改为需要 Integers而不是通用的 Object你通常会得到并增加类型安全。

关于java - 如何解决 "Unhandled exception type ClassNotFoundException"和 "Vector is a raw type"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com