java.lang.ClassCastException: cn.edu.bitc.ict.dcs.eas.teas.entity.Users
我的是SSH框架,搞不清这是什么问题,Users是个实体类。
18 个解决方案
#1
类型转换错误.... 没看到出错的详细信息, 无法判断是哪里转换出的错
#2
严重: Servlet.service() for servlet default threw exception
java.lang.ClassCastException: cn.edu.bitc.ict.dcs.eas.teas.entity.Users
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.Printer.toString(Printer.java:65)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:256)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:149)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:926)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:917)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: cn.edu.bitc.ict.dcs.eas.teas.entity.Users
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.Printer.toString(Printer.java:65)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:256)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:149)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:926)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:917)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
#3
但是我找了,基本不会出现这种错误
#4
之间传的就是Users这个类的对象,返回的是List
#5
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
到你自己这三个类里面仔细检查下.! 有的时候是一不小心就出错的
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
到你自己这三个类里面仔细检查下.! 有的时候是一不小心就出错的
#6
#7
呵呵,解决了,有确实有个地方错了,调用的方法错了。呵,谢了
#8
但是,还是有点问题,我是个登录的功能,无论输入什么都能登录
,我试过,肯定是能访问数据库的,为什么呢??
,我试过,肯定是能访问数据库的,为什么呢??
#9
这是我ACTION类中的方法
public String findUsers(){
users = new Users();
usersList = usersService.usersList(users);
if(usersList.size()>0){
return "success";
}else
{return "error";}
}
public String findUsers(){
users = new Users();
usersList = usersService.usersList(users);
if(usersList.size()>0){
return "success";
}else
{return "error";}
}
#10
类型转换异常~~~~~~~~~~~~~
#11
问题已经彻底解决,谢谢帮忙
#12
建议楼主 在进行类型转换的时候 先用instansof 来判断当前对象是否是你想要的类型 这样就会避免出错啦
#13
+1
#14
解决了就好
#15
看来上面的人都是高手啊 呵呵
#16
解决了就结贴啊
#17
12 楼说的好..
#18
类型转换异常
#1
类型转换错误.... 没看到出错的详细信息, 无法判断是哪里转换出的错
#2
严重: Servlet.service() for servlet default threw exception
java.lang.ClassCastException: cn.edu.bitc.ict.dcs.eas.teas.entity.Users
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.Printer.toString(Printer.java:65)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:256)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:149)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:926)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:917)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: cn.edu.bitc.ict.dcs.eas.teas.entity.Users
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.Printer.toString(Printer.java:65)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:256)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:149)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:926)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:917)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
#3
但是我找了,基本不会出现这种错误
#4
之间传的就是Users这个类的对象,返回的是List
#5
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByProperty(UsersDAO.java:98)
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
到你自己这三个类里面仔细检查下.! 有的时候是一不小心就出错的
at cn.edu.bitc.ict.dcs.eas.teas.dao.UsersDAO.findByUsername(UsersDAO.java:109)
at cn.edu.bitc.ict.dcs.eas.teas.service.UsersServiceImpl.usersList(UsersServiceImpl.java:57)
到你自己这三个类里面仔细检查下.! 有的时候是一不小心就出错的
#6
呵呵,这里有一个链接,也是和你的问题一样的。看看吧
http://topic.csdn.net/t/20020913/18/1021747.html
另外请再看下面的链接,都是有关你这个问题的 http://www.google.com.hk/search?hl=zh-CN&source=hp&q=classcastexception+%E6%98%AF%E4%BB%80%E4%B9%88%E5%BC%82%E5%B8%B8&meta=&aq=1&aqi=g10&aql=&oq=ClassCastException&gs_rfai=
另外请再看下面的链接,都是有关你这个问题的 http://www.google.com.hk/search?hl=zh-CN&source=hp&q=classcastexception+%E6%98%AF%E4%BB%80%E4%B9%88%E5%BC%82%E5%B8%B8&meta=&aq=1&aqi=g10&aql=&oq=ClassCastException&gs_rfai=
#7
呵呵,解决了,有确实有个地方错了,调用的方法错了。呵,谢了
#8
但是,还是有点问题,我是个登录的功能,无论输入什么都能登录
,我试过,肯定是能访问数据库的,为什么呢??
,我试过,肯定是能访问数据库的,为什么呢??
#9
这是我ACTION类中的方法
public String findUsers(){
users = new Users();
usersList = usersService.usersList(users);
if(usersList.size()>0){
return "success";
}else
{return "error";}
}
public String findUsers(){
users = new Users();
usersList = usersService.usersList(users);
if(usersList.size()>0){
return "success";
}else
{return "error";}
}
#10
类型转换异常~~~~~~~~~~~~~
#11
问题已经彻底解决,谢谢帮忙
#12
建议楼主 在进行类型转换的时候 先用instansof 来判断当前对象是否是你想要的类型 这样就会避免出错啦
#13
+1
#14
解决了就好
#15
看来上面的人都是高手啊 呵呵
#16
解决了就结贴啊
#17
12 楼说的好..
#18
类型转换异常