i=paymenthome.findBymaxidweb().iterator() ;
 if(i.hasNext()){
payment     =(Payment)PortableRemoteObject.narrow(i.next(),Payment.class);
Idweb[j]         =(int)payment.getIdweb();
}
 }catch(Exception ne){
System.out.println("paymentmaxidweb Exception"+ne.toString());
info =info+"调用PaymentFmaxidweb()方法时异常:"+ne.toString()+"<br>";
 }你先判断一下.前面的是不是返回的为null。

解决方案 »

  1.   

    我判断过了,Collection返回的不是空,可是写完.iterator()之后,就连写判断.isEmpty()都会报异常。不知道怎么回事?
      

  2.   

    我感觉你还是没有得到home对象,才回这样的,另外,建议不要直接用findall,你可以定义成自己的函数名字,在试试
      

  3.   

    public AttributeVO[] getAllAttributes() {
            Collection col    = null;
            AttributeVO []atV = null;
            Attribute at      = null;        try{
                col = attrLocalHome.findAllAttributes();
            }catch(FinderException fe){        }        atV = new AttributeVO[col.size()];
            Iterator it = col.iterator();
            for(int i = 0; it.hasNext(); i++){
                at         = (Attribute) it.next();
                int attrId = at.getAttrId();            atV[i] = getAttributeByAttributeId(attrId);
            }        col = null;
            at  = null;        return atV;
        }
      

  4.   

    我也知道这么写,但每次写到Iterator it = col.iterator();就会报异常,返回空值。
      

  5.   

    iterator()什么意思?在CMP中有findall方法吗?那么在weblogic_cmp_rdbms.xml中如何设置?
    我正遇到这些问题,希望各位高手解释一下吧。
    我在weblogic_cmp_rdbms.xml中是这样写的:
    <finder>
          <finder-name>findAllTermID</finder-name>
           <finder-query>SELECT TermID FROM Term_TABLE </finder-query>
     </finder>
      

  6.   

    建议你将i=paymenthome.findBymaxidweb().iterator() ;
    写成:if (paymenthome!=null){
             Collection colPayment = paymenthome.findBymaxidweb()
             if ((colPayment!=null)&&(!colPayment.isEmpty())){
              i= colPayment.iterator();  
    }
    else
    ...;}else
    ...;
      

  7.   

    我给个简单例子吧:
    实体bean的findall:
    public Collection ejbFindByAll() throws FinderException 
    {
      Connection con = null;
      PreparedStatement ps = null;
      ArrayList list = new ArrayList();  try
      {
        con = getConnection();
        ps = con.prepareStatement("select id , balance , address ,sex , age from tax");
        ResultSet rs = ps.executeQuery();
        while(rs.next())
        {
          this.accountId=rs.getString(1);
          list.add(rs.getString(1));
        }
        rs.close();
        return list;
      }
      catch(SQLException sqe)
      {
        log("FindByAll SQLException:"+sqe);
        throw new EJBException(sqe);
      }
      finally
      {
        cleanup(con,ps);
      }
    }
    session bean中对实体bean中的调用:
    blic Collection findAll() throws RemoteException
    {
    java.util.ArrayList m_return = new java.util.ArrayList() ;
    try
    {
      InitialContext initial = new InitialContext();
      Object  objRefTaxBean = initial.lookup("TaxBean");
      TaxHome taxhome = (TaxHome) PortableRemoteObject.narrow(objRefTaxBean,TaxHome.class);  java.util.Collection cl = taxhome.findByAll();
      System.out.println("Find end ");
      java.util.Iterator it = cl.iterator();
      while( it.hasNext())
      {
        java.util.ArrayList m_item = new java.util.ArrayList() ;
        Tax tax = (Tax)it.next();
        m_item.add(tax.getId());
        m_item.add(String.valueOf(tax.getBalance()));
        m_item.add(tax.getAddress());
        m_item.add(tax.getSex());
        m_item.add(tax.getAge());
        m_return.add(m_item);
      }
    }
    catch(NamingException e)
    {
      System.out.println("findAll error="+e);
      throw new EJBException(e);
    }
    catch(Exception e)
    {
      throw new EJBException(e);
    }
    return m_return ;
    }
      

  8.   

    上面的朋友写的是BMP中的findAll()方法,其实实现CMP中的findAll()方法更简单,只要写好相应的EQL语句。Session Bean中的findAll()方法就按照上面的例子,要注意Session Bean中的find方法不能简单地返回由Entity Bean中findAll()方法所发送的Collection,要转为ArrayList。
    推荐一个网站,上面有一个CMP/CMR系列教程,非常不错!
    http://www-900.ibm.com/developerWorks/cn/java/index.shtml
      

  9.   

    to  kexsong(剑走偏锋)
    按照你的方式,返回的结果都是最后一条纪录!如何能不这样?