Eclipse开发Java出现异常解决小结

以下是我在Eclipse开发Java过程中遇到的一些异常,今天先把它整理出以下几条:

1、java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

解决:必须将mysql的 .jar包复制到lib文件夹下

2、java.lang.IllegalStateException: Cannot forward after response has been committed

中文意思就是已经有提交了,不能够再次转向了

解决:转发 或者 重定向的时候,需要在后加一个retrun 即可。

服务器中不允许多次跳转

3、while(result.next())报空指针异常

解决:检查sql语句是否正确

4、java.lang.NumberFormatException: For input string: " 94"

将字符串转换为number的时候格式化错误,可能是长度有误,可能是不符合规则

解决:加trim()去空格;

5、异常:java.sql.SQLException: Before start of result set

解决:得到的结果集,必须循环遍历拿到结果

6、Cookie中保存对象的问题

解决:做项目过程中,用户登陆之后,需要将用户的信息存到Cookie中,但因为Cookie中只能存储字符串,所以想到了先把用户实体序列化成Json串,存储在Cookie中,用到的时候再拿出来反序列化。

7、异常:java.lang.ClassNotFoundException: com.jelly.web.AddServlet

解决:检查配置文件:web.xml中类的路径:全限定类名

8、java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

解决:传的问号的没有参数参数不能写Object[] param = {“”};

要写成Object[] param = {}

Eclipse 的详细介绍请点这里
Eclipse 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2017-12/149879.htm