`

java.lang.ClassCastException: java.util.ArrayList cannot be cast to cn.com.stari

    博客分类:
  • Java
阅读更多

错误处理

java.lang.ClassCastException: java.util.ArrayList cannot be cast to cn.com.starit.gis.entity.GeoInfo

 

返回的是List

public List<GeoInfo> selectByLike(String name){
        Session session = HbnUtil.getSession();   
//        List<GeoInfo> list = new ArrayList<GeoInfo>();
        StringBuffer hql = new StringBuffer();
        hql.append("from GeoInfo e where 1=1 and geoId<19");
        if(null !=name){
            hql.append(" and e.geoName like '%"+name+"%'");
        }
        Query query = session.createQuery(hql.toString());
        List<GeoInfo> geoInfoName= query.list();
//        System.out.println("测试打印的值:");
       
        //测试用
//         for(int i=0;i<geoInfoName.size();i++){
//                String name1 = geoInfoName.get(i).getGeoName();    //geoInfoName是一个大的集合,get(i)是指第i个值。getGeoName()则是get(i)中的属性值。
//                Double x1 = geoInfoName.get(i).getX();//获得经纬度
//                Double y1 = geoInfoName.get(i).getY();
//                System.out.println(name1);
//                System.out.println(x1);
//                System.out.println(y1);
//            }
         
        HbnUtil.closeSession();
        return geoInfoName;
    }

 

在action中用调用:

    List<GeoInfo> geoInfoName =  geoInfoDao.selectByLike(name2);
       
//            GeoInfo geoInfoName = (GeoInfo) geoInfoDao.selectByLike(name2);
           
            System.out.println("怎么打印不出来呢???"+geoInfoName);
            Double xx = geoInfoName.getX();
            System.out.println(xx);

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics