JAVA错误处理大集合

0、 需要标识符

a) 不在函数内

1、 非法表达式开始

b) 可能:丢失括号 .

2. no data found

a) 可能:setint(1,100)中,没有100这个值

3. 找不到符号

a) 可能:没导入包

4. 指定了无效url

a) 可能:数据库名或ip错误,即连接出错

5. 类路径没有找到

a) 可能: classnotfoundexception: oracle.jdbc.driver.oracledriver

b) 原因: 一般是指包名写错,或者没有import包,或者没有在类路径中找到jar文件

c) 解决: 没有加载oracle驱动jar,在.bash_profile中把ojdbc14.jar加进来

6. 空指针异常

a) 可能: 数据源错误 比如数据库名或ip错误

7. 不能执行查询

a) 可能: 数据库中表的问题,比如列名不存在

8. invalid identity

a) 可能: 列名出错

9. 若在数据库中创建了 两个sequence ,运行时出现异常可能是先后执行了多次select语句,导致与原有的序列号产生冲突

10. 表名或列名不存在

a) 可能:表不存在或者没有插入数据到表中

11. 不支持的类,类的版本错误

a) 可能:没有导入jdk5.0,或者编译器仍为1.4

12. mappingnotfoundexception

a) maybe: in the eclipse not refersh , or not exist in the dirctory

13. hibernateexception: /hibernate.cfg.xml not found

a) maybe1: hibernate.cfg.xml not in the root directory

b) maybe2: could not parse configuration .

c) resolve: database not connect or use another database

14. constraintviolationexception

a) maybe: used a not true database

15. 驱动没有找到 或者 jdbc driver not found

可能:连接数据库的驱动jar包不存在或者版本不一致,比如将旧的版本换成新的会造成该类错误

16. 空指针异常 , java.lang.nullpointerexception

a) 可能1:数据库连接出错,比如在hibernate.cfg.xml中的数据错误会导致异常。

17. 数据插入异常 ,genericjdbcexception: could not insert

a) 可能1:没有建立表或者表中没有任何数据

b) 可能2:插入数据后没有执行提交语句:commit

18. lazyinitializationexception 或者延迟加载异常

a) 可能1:没有在查询语句中加fetch

19. identifiergenerationexception

a) 可能1:高位表没有初始化(比如hi_value中没有记录)

20. could not initialize a collection: [hibernate.entity.role.modules#32768] syntax error: encountered "-" at line 1, column 132.

a) 错误原因:红色字部分中“-”为非法字符,替换为module_role

21. could not insert collection rows: [hibernate.entity.module.roles#1]

在module.hbm.xml文件的如下配置中加入inverse=”true”

22.在部署struts时,出现如下错误信息:

http status 404 - servlet action is not available

type status report

message servlet action is not available

description the requested resource (servlet action is not available) is not available.

问题原因:

1.、web.xml文件中未配置actionservlet。

2、struts-config.xml文件未配置你要访问的action。

3、你的jsp文件form标记中action属性的路径名称错误。

4、非以上三种情况。

针对以上4种情况相应的解决方案如下:

1、在web.xml文件中加上actionservlet的配置信息

?????? /web-inf/struts-config.xml?

?2、在struts-config.xml文件检查你要访问的action配置文件。

3、检查jsp文件form标记中action属性的路径名称是否与struts-config.xml文件中action标记的path属性的路径名称一致。

4、非以上情况的解决办法就是检查web容器的log日志,如果时tomcat则检查下logs目录下的localhost_log文件,看里边是否记录有错误信息,然后根据错误信息提示将其纠正。

23.java.lang.noclassdeffounderror: org/apache/commons/beanutils/converter

缺少spring-framework-2.0.3\lib\jakarta-commons\commons-beanutils.jar

24.

ava 代码caused by: java.lang.noclassdeffounderror: org/objectweb/asm/type

缺少spring-framework-2.0.3\lib\asm\asm-2.2.2.jar包,版本不同,该包的名字有相应的区别

java 代码caused by: java.lang.noclassdeffounderror: org/dom4j/documentexception

缺少spring-framework-2.0.3\lib\dom4j\dom4j-1.6.1.jar包,版本不同,该包的名字有相应的区别

把这个包进去就可以了:\spring206\lib\dom4j、dom4j-1.6.1.jar

java 代码caused by: java.lang.noclassdeffounderror: org/apache/commons/collections/sequencedhashmap

缺少spring-framework-2.0.3\lib\jakarta-commons\commons-collections.jar包,版本不同,该包的名字有相应的区别

java 代码caused by: java.lang.noclassdeffounderror: net/sf/cglib/proxy/callbackfilter

缺少spring-framework-2.0.3\lib\cglib\cglib-nodep-2.1_3.jar包,版本不同,该包的名字有相应的区别

java 代码caused by: java.lang.noclassdeffounderror: org/objectweb/asm/codevisitor

缺少hibernate-3.2\lib\asm.jar包,版本不同,该包的名字有相应的区别

java 代码

org.hibernate.exception.sqlgrammarexception: could not load an entity: [www.proudsoul.xml.user#1]

java工程与web工程包的区别:一个是asm.jar,一个是jta.jar

java 代码caused by: java.lang.noclassdeffounderror: javax/transaction/transactionmanager

缺少spring-framework-2.0.3\lib\j2ee\jta.jar包,版本不同,该包的名字有相应的区别此种错误请检查相应的***.hbm.xml配置文件的配置

25,

exception in thread "main" org.springframework.dao.invaliddataaccessresourceusageexception: could not get next sequence value; nested exception is org.hibernate.exception.sqlgrammarexception: could not get next sequence value

caused by: org.hibernate.exception.sqlgrammarexception: could not get next sequence value

原因:没有加sequence或者数据库的方言写错了

26,

我的配置文件

然后我运行保存一条数据进去

the database returned no natively generated identity value

就会报这个错误

因为你native是根据看底层数据库的能力选择identity, sequence 或者hilo中的一个

而我建表的时候id没有指定

alter table `student` change `id` `id` int auto_increment

我们把我们的表的结构小小的改动一下就没问题了

27,

updatemanager无法启动2007-08-09 15:21如果在应用程序安装过程中,暴力中断安装程序,会出现如下状况:1.apt-get remove 和dpkg --remove 无法删除软件 2.updatemanager无法启动3.新立得软件包管理程序无法启动

以上可能是deb损坏之类造成的

sudo dpkg -r sqldveloper

正在读取软件包列表... 完成

正在分析软件包的依赖关系树... 完成

e: 软件包 sqldeveloper 需要重新安装,但是我无法找到相应的安装文件。

解决方法:1.从 /var/lib/dpkg/status 中把对应的段删掉

重要:修改之前请先备份

在status中找到你对应的包删除就ok了...

28,

exception in thread "main" java.lang.noclassdeffounderror: antlr/antlrexception

少了antlr-2.7.5h3.jar包,从d:\eclipse\eclipse\plugins\com.genuitec.org.hibernate.eclipse_4.1.1\myeclipse-data\3.0\lib

29,

caused by:

java.lang.noclassdeffounderror: javax/transaction/synchronization

缺少spring206\lib\j2ee\jta.jar

30,

caused by:

java.lang.illegalargumentexception: cannot convert value of type [$proxy3] to required type [business.impl.pricebiz] for property 'pricebiz': no matching editors or conversion strategy found

在java类中设置pricebiz时应该设置的是接口pricebizif,而非实现类

18, 数组越界

可能1: 在命令行后面需要加入参数.

可能2:加入的参数错误

19, car is not mapped

可能1: 在cfg.xml中没有增加映射的hbm.xml文件在中

20, 属性没有找到

可能1: hbm.xml文件中的

有问题, 也许是name的值与对应类中的成员名不一致

21,sqlexception: 无当前连接可能1:在比如创建帐户时没有对相应的方法添加到中去,比如这个没有加入:newaccount

transfer

22,sqlexception: syntax error: encountered "table" at line 1, column 8.

可能1;执行sql时出现冲突,可能是sql语句中使用了关键字作为变量来用,比如

update order set balance=1000000;

其中order被用作表名来使用,这是错误的,因为order是个关键字,用在order by中

23, servlet /spring-webmvc threw load() exception

org.xml.sax.saxparseexception: document root element "beans", must match doctype root "null".

jar包的冲突,spring-1.2.6.jar和spring.jar出现在一个war的目录中:jboss/server/all/deploy/spring-webmvc.war/web-inf/lib

24, java.sql.sqlexception: 当事务仍处于活动状态时,无法关闭连接。

25 ,

validatejarfile(/home/soft01/tomcat/webapps/sms-token-struts/web-inf/lib/servlet-api.jar)

servlet /sms-struts-tiles threw load() exception

java.lang.classnotfoundexception: org.apache.struts.action.actionservlet

原因:在web-inf/lib/ 目录下有servlet-api.jar与/tomcat/common/lib目录下的servlet-api.jar冲突了,把web-inf/lib/下的servlet-api.jar删除就可以了

26,java.lang.classnotfoundexception: org.springframework.web.struts.contextloaderplugin

marking servlet action as unavailable

10:30:47,088 error [/netct_oss]:3953 - servlet /netct_oss threw load() exception

javax.servlet.unavailableexception

27,org.xml.sax.saxparseexception: document root element "beans", must match doctype root "null".

缺少myeclipse/eclipse/plugins/com.genuitec.eclipse.springframework_5.5.0/data/2.0/dist/modules/spring-struts.jar

28,caused by: java.sql.batchupdateexception: ora-02291: integrity constraint (sd0702.fk82d343cf49a4b831) violated - parent key not found

caused by: org.hibernate.exception.constraintviolationexception: could not execute jdbc batch update

有可能是id生成策略的问题,我将它xml映射文件改成就好了

29,

2007-08-19 16:21:43,290 error [org.apache.catalina.core.containerbase.[catalina].[localhost].[/oss].[action]] - servlet.service() for servlet action threw exception

org.hibernate.nonuniqueobjectexception: a different object with the same identifier value was already associated with the session: [entity.module#2]

java.util.concurrentmodificationexception

原因:已经有对象拥有了所选择的module,用clear(),而不是remove();

30,

error [org.apache.catalina.session.managerbase] - ioexception while loading persisted sessions: java.io.invalidclassexception: entity.module; local class incompatible: stream classdesc serialversionuid = -5988350031935445758, local class serialversionuid = -297934247726484429

java.io.invalidclassexception: entity.module; local class incompatible: stream classdesc serialversionuid = -5988350031935445758, local class serialversionuid = -297934247726484429

在module中加上一个关键字:transient

31,

caused by: java.sql.batchupdateexception: ora-02292: integrity constraint (sd0702.sys_c00132664) violated - child record found

原因:有其他的表引用了该表的外建,所以报这个异常,如果没有引用就不会出现

32,

出现数组越界的时候,看看是不是循环时没有加=,比如:

for(int i = 1; ihttp://displaytag.sourceforge.net/

下载displaytag.jar和displaytag.tld

displaytag.jar放在lib目录,而displaytag.tld放在web-inf目录,在web.xml中为displaytag.tld声明一下。

http://displaytag.org

/web-inf/displaytag.tld

在jsp里使用前,加上

注意该软件有个bug,他要用的一个包common-lang.jar版本必须在2.0以上。

如果碰到下面异常,则应坚持一下是否该包的版本问题。

java.lang.nosuchmethoderror: org.apache.commons.lang.stringutils.capitalize(ljava/lang/string;)ljava/lang/string;

然后就可放心使用了

其中xxx为对象中的带有getter的变量>。

定义表格的样子,用css定义。如

table.its thead tr {

background-color: #69c

}

table.its tr.even {

background-color: #def

}

在使用分页时,可能会出现这种情况,点击其他页时,弹出下载窗口,让你下载当前jsp页面,这是因为你在当前页面读取了数据的缘故。解决办法为在action里读取数据而不是在jsp里。可以参考

http://www.displaytag.org/example-paging.jsp?d-26189-p=2

17.使用displaytag时,在一列中放入多个元素

必须在display:table中定义一个id

" target = "_blank" >查看

">编辑

">删除

要在displaytag中使用链接,必须具备paramid,否则不显示为链接

可以这样使用display

其中product为对象

18. 可以直接取到session.getattribute()取到的东西。

19.实验struts-upload例子时要注意的地方:

1.if you would rather write this file to another file, please check here:

这一行要打钩

2.if you checked the box to write to a file, please specify the file path here:

在这里要重命名如:c:\b.jpg

上传成功的话,会出现提示 the file has been written to "c:\b.jpg"

20.hibernate的like可以这么用:

query query = session.createquery("from src.persistent.book as book where upper(book.name) like :name ");

query.setstring("name", "%");

result = query.list();

21.hibernate出现 duplicate import : classname

异常也可能是因为忘了为持久类在configuration中addclass了

22.

name所引用的是session里的attribute。

23.如果发现要出现询问下载的情况,有可能是因为要跳转的页面出现了问题。试试在要跳转到的页删掉

24.如果jsp页面跳转时出现下边的错误信息:

the request sent by the client was syntactically incorrect (invalid path /web/shoppingcart was requested).

原因是struts-config的action = "x" 写成了 action = "x.do"

25.在struts中,strut-config.xml中,forward时使用redirect = "true"可以将.do重定向为.jsp

26.以后在判断相等性之前先用logger把两个值显示出来。

27.从session里getattribute后,修改并不需要重新setattribute一次。

28.在hibernate中使用subclass是一棵继承树共用一个表,仅生成个mapping。

每个类中必须有discrimator-value。在最上层的类中必须声明:

@hibernate.discriminator column = "class"。

不可以将子类添加到configuration里去。(即不可addclass(子类))

使用xdoclet的建立subclass的例子(该类是父类)

/**

* @hibernate.class discriminator-value = "customer"

* @hibernate.discriminator column = "class"

*/

而使用joined-subclass则是一类一表,也不许将子类添加进configuration里去。

/**

* @hibernate.joined-subclass

* @hibernate.joined-subclass-key

* column="customer_id"

*/

如果发现生成的mapping文件中joined-subclass的key column为空,那么可能是@hibernate.joined-subclass-key这句没有写对。

用joined-subclass生成的表,仔细看。member extends customer

create table customer (

id varchar2(255) not null,

name varchar2(255),

description varchar2(255),

primary key (id)

)

create table member (

customer_id varchar2(255) not null,

password varchar2(255),

primary key (customer_id)

)

29.在junit中尽量使用assertequals代替asserttrue;

30.hibernate

如果child extends parent

那么from parent as parent 也将会将child选出来,而from child as child 则不会选出parent

31.hibernate

使用hibernate的one-to-one时,应该两方向都set,否则会报save nullpointexception

parent.setchild(child);

child.setparent(parent);

32.hibernate

遇到下边的异常,估计是与因为外键出现了问题:

java.lang.nullpointerexception

at net.sf.hibernate.persister.abstractentitypersister.getpropertyvalue(abstractentitypersister.java:675)

at net.sf.hibernate.id.foreigngenerator.generate(foreigngenerator.java:33)

如:

* @hibernate.id generator-class = "foreign"

* @hibernate.generator-param name = "property" value = "customer"

* @hibernate.one-to-one name = "custmoer" class = "src.persistent.customer"

value的值和one-to-one 中name的值不符,则会出现上边的异常。如果不显示指定name则默认取成员变量名

customer a

则name = "a" 需要小心的是不是类名。所以,以后最好显示指定名字为好。

33.出现异常:

exceptionobject references an unsaved transient instance - save the transient instance before flushing: src.persistent.product

原因没有为某对象进行set设置, 如上边的这个就是某对象没有调用setproduct

34.

"xxx action = "/a" 不用.do和根目录名

http://forum.hibernate.org.cn/viewtopic.php?t=1772

query q = s.find(".....");

q.setfirstresult(10);//从第11条记录开始

q.setmaxresults(100);//取出100条

......

38.struts的validate最简单实现

1.首先准备好错误提示信息。

xxx.properties 里

errors.required={0} is required.(默认已有)

2.form必须从validatorform继承

3.不可以重载validatorform的validate函数

4.在validate.xml中为你想验证的表单进行验证设计。例如

好文要顶关注我收藏该文与我联系


======================================================
在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定 这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值