]]>java常见错误以及(qing)可能原因集锦http://www.tkk7.com/kylixlu/archive/2008/01/18/176185.html陆昱?/dc:creator>陆昱?/author>Fri, 18 Jan 2008 05:25:00 GMThttp://www.tkk7.com/kylixlu/archive/2008/01/18/176185.htmlhttp://www.tkk7.com/kylixlu/comments/176185.htmlhttp://www.tkk7.com/kylixlu/archive/2008/01/18/176185.html#Feedback0http://www.tkk7.com/kylixlu/comments/commentRss/176185.htmlhttp://www.tkk7.com/kylixlu/services/trackbacks/176185.html 0?需要标识符
a) 不在函数?
1?非法表达式开?
b) 可能:丢失括号 .
2. no data found
a) 可能:setInt(1,100)?没有100q个?
3. 找不到符?
a) 可能:没导入包
4. 指定?jin)无效URL
a) 可能:数据库名或IP错误,卌接出?
5. c\径没有找?
a) 可能: ClassNotFoundException: oracle.jdbc.driver.OracleDriver
b) 原因: 一般是指包名写?或者没有import?或者没有在c\径中扑ֈjar文g
c) 解决: 没有加蝲Oracle驱动jar,?bash_profile中把ojdbc14.jar加进?
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
可能Q连接数据库的驱动jar包不存在或者版本不一_(d)比如旧的版本换成新的会(x)造成该类错误
16. I指针异?Q?java.lang.NullPointerException
a) 可能1Q数据库q接出错Q比如在hibernate.cfg.xml中的数据错误?x)导致异常?
17. 数据插入异常 QGenericJDBCException: could not insert
a) 可能1Q没有徏立表或者表中没有Q何数?
b) 可能2Q插入数据后没有执行提交语句Qcommit
18. LazyInitializationException 或者gq加载异?
a) 可能1Q没有在查询语句中加fetch
19. IdentifierGenerationException
a) 可能1Q高位表没有初始化(比如hi_value中没有记?
20. could not initialize a collection: [hibernate.entity.Role.modules#32768] Syntax error: Encountered "-" at line 1, column 132.
a) 错误原因Q?lt;set name="modules" table="module-role" lazy="false">U色字部分中“-”为非法字W,替换为module_role
21. could not insert collection rows: [hibernate.entity.Module.roles#1]
在Module.hbm.xml文g的如下配|中加入inverse=”true”
<set name="roles" table="module_role" inverse="true">
22Q在部vStrutsӞ出现如下错误信息Q?
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.
问题原因Q?
1.、web.xml文g中未配置ActionServlet?
2、struts-config.xml文g未配|你要访问的Action?
3、你的jsp文gform标记中action属性的路径名称错误?
4、非以上三种情况?
针对以上4U情늛应的解决Ҏ(gu)如下Q?
1、在web.xml文g中加上ActionServlet的配|信?
?????? /WEB-INF/struts-config.xml?
?2、在struts-config.xml文g(g)查你要访问的Action配置文g?
3、检查jsp文gform标记中action属性的路径名称是否与struts-config.xml文g中action标记的path属性的路径名称一致?
4、非以上情况的解军_法就是检查web容器的log日志Q如果时tomcat则检查下logs目录下的localhost_log文gQ看里边是否记录有错误信息,然后Ҏ(gu)错误信息提示其U正?
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
原因Q没有加Sequence或者数据库的方a写错?
26,
我的配置文g
<id name="id" column="id">
<generator class="native" />
</id>
然后我运行保存一条数据进?
The database returned no natively generated identity value
׃(x)报这个错?
因ؓ(f)你native是根据看底层数据库的能力选择identity, sequence 或者hilo中的一?
而我的时候id没有指定
alter table `student` change `id` `id` int auto_increment
我们把我们的表的l构小的改动一下就没问题了(jin)
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
?span class="hilite1">javacM讄priceBiz时应该设|的是接口PriceBizIfQ而非实现c?
31, 数组界
可能1: 在命令行后面需要加入参?
可能2:加入的参数错?
32, car is not mapped
可能1: 在cfg.xml中没有增加映的hbm.xml文g?lt;mapping.../>?
33, 属性没有找?
可能1: hbm.xml文g中的 <property name =""> 有问? 也许是name的g对应cM的成员名不一?
35,SQLException: Syntax error: Encountered "table" at line 1, column 8.
可能1;执行SQL时出现冲H?可能?span class="hilite2">SQL语句中用了(jin)关键字作为变量来?比如
update order set balance=1000000;
其中order被用作表名来使用,q是错误?因ؓ(f)order是个关键?用在order by?
36, 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
40,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
41,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映射文gҎ(gu)<generator class="increment" />好?
42,
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
原因:已经有对象拥有了(jin)所选择的module,用clear(),而不是remove();
43,
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
44,
Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (SD0702.SYS_C00132664) violated - child record found
原因:有其他的表引用了(jin)该表的外?所以报q个异常,如果没有引用׃?x)出?
45,
出现数组界的时?看看是不是@环时没有?,比如:
for(int i = 1; i<arr.length;i++)可以Ҏ(gu)
for(int i = 1; i<=arr.length;i++)
46.如果使用Ant和Junit是被报找不到test,(g)查一下是否误用了(jin)private
出错信息Q?
<failure message="No tests found in test.AllTest" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: No tests found in test.AllTest
该错误有个很特别的特点,当你不通过ant来运行测试,而是通过AllTestcLq行的话Q可以正常运行。小?j)?
49.心(j)下边的异常,
exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of xp.bean.Users.?" type="net.sf.hibernate.PropertyAccessException">java.lang.ClassCastException at xp.bean.UsersMetaClass1.setPropertyValues(<generated>) at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues
上次出现该错错误的原因是:
源文仉我的classcdZ个类Contact contact
而跑到mapping里却成了(jin)Set,呵呵厉害?
50.H然间冒出大量的NullPointException
重新build一下?
51.="Flush during cascade is dangerous - this might occur if an object was deleted and then re-saved by cascade"
52.Tapestry的出错信息:(x)
Class com.bookshop.Hello does not implement the IPage interface.
location: context:/WEB-INF/Home.page, line 6
原因Q与昄有关的哪?span class="hilite1">javacL有从IPage家族l承?
62.使用displaytagӞ在一列中攑օ多个元素
必须在display:table中定义一个id
<display:table name = "allBooks" class = "its" pagesize = "5" id = "item">
<display:column title = "操作">
<a href = "/Bookshop/admin/bookManagement.do?action=view&id=<%=((Book)item).getId()%>" target = "_blank" >查看</a>
<a href = "/Bookshop/admin/bookManagement.do?action=edit&id=<%=((Book)item).getId()%>">~辑</a>
<a href = "/Bookshop/admin/bookManagement.do?action=delete&id=<%=((Book)item).getId()%>">删除</a>
</display:column>
要在displaytag中用链接,必须具备paramIdQ否则不昄为链?
<display:column property = "product.name" href = "viewDetailV2.0.jsp" title = "书名" paramId="item" paramProperty="product.id"/>
可以q样使用display
<display:column property = "product.id" title = "ID"/>
其中product为对?
63.<bean:write name = "xxxx" property = "xxx"/> 可以直接取到session.getAttribute()取到的东ѝ?
64.实验struts-upload例子时要注意的地方:(x)
1.If you would rather write this file to another file, please check here:
q一行要打钩
2.If you checked the box to write to a file, please specify the file path here:
在这里要重命名如Qc:\b.jpg
上传成功的话Q会(x)出现提示 The file has been written to "c:\b.jpg"
65.Hibernate的like可以q么用:(x)
Query query = session.createQuery("from src.persistent.Book as book where upper(book.name) like :name ");
query.setString("name", "%");
result = query.list();
69.如果JSP面跌{时出C边的错误信息Q?
The request sent by the client was syntactically incorrect (Invalid path /web/shoppingCart was requested).
原因是struts-config的action = "x" 写成?action = "x.do"
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的gW,则会(x)出现上边的异常。如果不昄指定name则默认取成员变量?
?
Customer a
则name = "a" 需要小?j)的是不是类名。所以,以后最好显C指定名字ؓ(f)好?
78.出现异常Q?
Exceptionobject references an unsaved transient instance - save the transient instance before flushing: src.persistent.Product
原因没有为某对象q行set讄Q?如上边的q个是某对象没有调用setProduct
83.服务器报
The requested resource (/xxxx/xxx.htm) is not available.的很奇怪的一个的可能原因
在web.xml中定义的tldQ没有找?
或者是lib目录下的包太多出C(jin)问题?
?
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/spring.tld</taglib-location>
</taglib>
如WEB-INF目录下不存在spring.tld的话Q就?x)报上边的错?
84.
spring的xxx-servlet.xml的用SimpleFormControllerpd的类问题Q?
<bean id = "priceIncreaseForm" class="PriceIncreaseFormController">
<property name="sessionForm"><value>true</value></property>
<property name="beanName"><value>priceIncrease</value></property>
<property name="commandClass"><value>PriceIncrease</value></property>
<property name="formView"><value>priceIncrease</value></property>
<property name="successView"><value>hello</value></property>
<property name="productManager">
<ref bean="prodMan"/>
</property>
</bean>
q里要注意几个问题:(x)
(1)上边的PriceIncrease是了(jin)cdQ必dclasses里存在该c,否则报:(x)
PropertyVetoExceptionsException: 1 errors:-- ErrorCodedPropertyVetoException: message=[Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property named 'commandClass'; nested exception is: java.lang.IllegalArgumentException: Invalid class name [PriceIncrease]: PriceIncrease]; errorCode=[typeMismatch] java.lang.IllegalArgumentException: Invalid class name [PriceIncrease]: PriceIncrease
(2)<property name="formView"><value>priceIncrease</value></property>
q一行必不可,priceIncrease是页面的名字Q他会(x)是prefix + priceIncrease + suffix
如果~少该行Q则报:(x) javax.servlet.ServletException: Error in ModelAndView object or View resolution encountered by servlet with name 'pocketSpring': View to render cannot be null with ModelAndView [ModelAndView: materialized View is [null]; Model=[{priceIncrease=PriceIncrease@148e798, org.springframework.validation.BindException.priceIncrease=org.springframework.validation.BindException: BindException: 0 errors}]]
使用Errors的rejectValue相关问题Q?
rejectValue(java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
Reject the given field of the current object, using the given error description.
当前对象指的是xxx-servlet.xml中与validatorcL联系的哪个对象?
W一个是Q当前对象的属性名Q必d?
W二个是Q将要从属性文件中d的消?
W三个是Q传递给所d的消息的参数Q如Q?
error.too-low=You have to specify a percentage higher than {0}!
W四个是Q当从属性文件中d消息不成功时Q所reject的?
以后从request中读取parameter可以借用spring的RequestUtils包里?
getStringParameter
public static java.lang.String getStringParameter(javax.servlet.http.HttpServletRequest request,
&bsp; java.lang.String name, java.lang.String defaultVal)
Get a string parameter, with a fallback value. Never throws an exception. Can pass a distinguished value to default to enable checks of whether it was supplied.
不会(x)抛异?
Hibernate的问题:(x)2.1rc的问?
INFO: cache provider: net.sf.ehcache.hibernate.Provider
net.sf.hibernate.HibernateException: could not instantiate CacheProvider:
解决办法Q?.1rc比以前的版本多需要一个包
ehcache.jar