如何解决"未处理的异常类型ClassNotFoundException的"和" Vector是原始类型"错误? [英] How to solve "Unhandled exception type ClassNotFoundException" and "Vector is a raw type" errors?

查看:522
本文介绍了如何解决"未处理的异常类型ClassNotFoundException的"和" Vector是原始类型"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在servlet的一面,我想收到来自applet发送的载体。在code是像

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();

该错误消息

在该行多个标记


      
  • 未处理的异常类型的ClassNotFoundException

  •   
  • Vector是原始类型。引用泛型类型矢量
       应参数

  •   
  • Vector是原始类型。引用泛型类型矢量
       应参数

  •   

这有什么错我的code?谢谢你。

What's wrong with my code? Thanks.

推荐答案

有关外,包住code在

For the exception, wrap your code in

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

其他的消息是警告,不会从编译停止程序。他们提到需要对parametrised类型的参数,坚持以新规格(如Java 1.5)。所以,如果你想存储整数向量,使用矢量&lt;整数GT; 。这改变了整数,而不是普通的对象的方法,需要你通常会得到并增加类型安全性。

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 requiring Integers instead of the generic Object you'd normally get and increases type-safeness.

这篇关于如何解决&QUOT;未处理的异常类型ClassNotFoundException的&QUOT;和&QUOT; Vector是原始类型&QUOT;错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆