java.lang.Integer cannot be cast to

问题描述

public List<Materials> findAllMaterialsByAppid(Integer appid) {String hql1 = "select medid from Materials where appid = ? and pid = 0";List<Materials> list = this.hibernateTemplate.find(hql1, appid);if (list != null && list.size() > 0) {if(list.get(0).getMedid() != null){Integer medid = (Integer)list.get(0).getMedid();String hql2 = "from Materials where appid = ? and pid = ?";return this.hibernateTemplate.find(hql2, appid, medid);}请教一下大家 问题补充:java.lang.ClassCastException: java.lang.Integer cannot be cast to com.gorgonor.modules.patients.entity.Materialsat com.gorgonor.modules.patients.dao.impl.MaterialsDaoImpl.findAllMaterialsByAppid(MaterialsDaoImpl.java:43)at com.gorgonor.modules.patients.service.impl.MaterialsServiceImpl.findAllMaterialsByAppid(MaterialsServiceImpl.java:22)at com.gorgonor.modules.patients.controller.DiskController.doctorDisk(DiskController.java:44)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)Materials属性private Integer medid;private Integer pid;private String title;private java.util.Date createtime;private Integer appid;private Integer filenum;private Integer filetotalsize;private String isprivate;private String creator;

解决方案

String hql1 = "from Materials where appid = ? and pid = 0";
解决方案二:
你SELECT 语句中是取 medid String hql1 = "select medid from Materials where appid = ? and pid = 0"; 但实际上你是相取是的Materials 这个对象这样的转换肯定有问题,你想要的SQL应该是这样的吧:String hql1 = "select * from Materials where appid = ? and pid = 0";
解决方案三:
最好贴完整一点,看看具体是哪一行报错。不过我猜测一下是不是这行的问题: Integer medid = (Integer)list.get(0).getMedid(); 你改为:Integer medid = (Integer)(list.get(0).getMedid()); 或者Integer medid = ((Materials)list.get(0)).getMedid(); 试试。
解决方案四:
Integer medid = (Integer)list.get(0).getMedid(); 应该是这行代码导致的。Materials中的属性medid是什么数据类型的?
解决方案五:
错误贴完整,Materials的各个属性贴上来

时间: 2024-09-13 17:58:13

java.lang.Integer cannot be cast to的相关文章

Ljava.lang.Integer;cannot be cast to java.lang.Integer:JPA查询参数设置请教

问题描述 我在使用JPA时,使用如下查询语句:Query query = em.createQuery(select bean from Content bean where bean.departmentId in (:departmentIds));然后设置参数:query.setParameter("departmentIds", departmentIds);这个departmentIds是Integer[]型的.程序运行时:提示 [Ljava.lang.Integer;can

no suitable HttpMessageConverter found for request type [java.lang.Integer]

今天在使用Spring Template的时候遇到了这个异常: no suitable HttpMessageConverter found for request type [java.lang.Integer] Google了一下然后在stackoverflow上面找到了解决方案: I have a method in Spring rest service. @RequestMapping(value = "test/process", method = RequestMetho

java.lang.Integer.toHexString(b[n] &amp;amp; 0XFF)中0XFF使用

byte[] b = {5,2,20,108}; String stmp = java.lang.Integer.toHexString(b[n] & 0XFF)   在32位的电脑中数字都是以32格式存放的,如果是一个byte(8位)类型的数字,他的高24位里面都是随机数字,低8位 才是实际的数据.java.lang.Integer.toHexString() 方法的参数是int(32位)类型,如果输入一个byte(8位)类型的数字,这个 方法会把这个数字的高24为也看作有效位,这就必然导致错

Hibernate中HQL语句查询指定字段值报错:ClassCastException: [java.lang.Object; cannot be cast to bean.PersonStatic

在有一次通过如下HQL语句进行查找相应字段时: String hql = "select sum(search),sum(geometry),sum(greedy), sum(graph),sum(number),sum(simulate),sum(combine),sum(structure) from PersonStatis ps where ps.ps_date>=? and ps.ps_date<?"; 通过Query中的方法list()返回一个List对象. 但

java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException

不是一个Exception,而是一个Error,要强制转成Exception类型,就出错了java.lang.NoClassDefFoundError  java.lang.RuntimeException 

TreeMap cannot be cast to java.lang.Comparable

    /** * Constructs a new, empty tree map, using the natural ordering of its * keys. All keys inserted into the map must implement the {@link * Comparable} interface. Furthermore, all such keys must be * <i>mutually comparable</i>: <tt>

java.lang.NumberFormatException: null

HTTP Status 500 - null type Exception report message null description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.NumberFormatException: null java.lang.Integer.parseInt(Integer.java:415

Hibernate查询,数据库中无数据正常,有数据出现java.lang.NullPointerException 空指针异常

hibernate执行表与表之间多对一的查询时,如果数据库中没有数据时,一切正常,一旦将数据插入到数据库中,查询的时候将会抛出空指针异常.以下是我的*.hbm.xml的配置 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http

ssh-学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助!

问题描述 学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助! SaveOfficeAction.java出错:java.lang.NullPointerException package we.app.action; import we.app.data.*; import com.opensymphony.xwork2.ActionSupport; public class SaveOfficeAction exten