当前位置: 代码迷 >> Java相关 >> 关于Iterator的next()方法,该如何处理
  详细解决方案

关于Iterator的next()方法,该如何处理

热度:7603   发布时间:2013-02-25 21:48:00.0
关于Iterator的next()方法
这种写法是不正确的,会报java.util.NoSuchElementException的错误。iterator.next()不能连续用,这个为什么
Java code
Iterator<T_Tms_TransIbp> iterator  = list.iterator();          while(iterator.hasNext()){                if(iterator.next().getCompanycode()==null){                   error.append("接口表中Companycode的必录项有空,");                                 }               else if(iterator.next().getSalechannelcode()==null){                   error.append("接口表中Salechannelcode的必录项有空,");                                }               if(iterator.next().getBillnumber()==null){                   error.append("接口表中Billnumber的必录项有空,");                                  }               if(iterator.next().getBillbooknumber()==null){                   error.append("接口表中Billbooknumber的必录项有空,");                                 }               if(iterator.next().getSeragentcode()==null){                   error.append("接口表中Seragentcode的必录项有空,");                                 }               if(iterator.next().getPhone()==null){                   error.append("接口表中Phone的必录项有空,");                                 }               if(iterator.next().getSersectioncode()==null){                   error.append("接口表中Sersectioncode的必录项有空,");                                   }               if(iterator.next().getSerteamcode()==null){                   error.append("接口表中Serteamcode的必录项有空,");                                  }               if(iterator.next().getPolicyholdername()==null){                   error.append("接口表中Policyholdername的必录项有空,");                                   }               if(iterator.next().getInsurecode()==null){                   error.append("接口表中Insurecode的必录项有空,");                                   }               if(iterator.next().getCerttypecode()==null){                   error.append("接口表中Certtypecode的必录项有空,");                                }               if(iterator.next().getChargetypecode()==2&&iterator.next().getBankcode()==null){                   error.append("CHARGETYPECODE=2转帐时,BANKCODE不能为空,");                                  }               if(iterator.next().getChargetypecode()==2&&iterator.next().getAccountname()==null){                   error.append("CHARGETYPECODE=2转帐时,Accountname不能为空,");                                   }               if(iterator.next().getChargetypecode()==2&&iterator.next().getAccounts()==null){                   error.append("CHARGETYPECODE=2转帐时,Accounts不能为空,");                                  }               if(iterator.next().getChargetype()==3&&iterator.next().getPeriodofvalidity()==null){                   error.append("ChargeType为信用卡时,PERIODOFVALIDITY, 信用卡缴费不能为空,");                                  }                if(iterator.next().getChargetype()==3&&iterator.next().getPeriodofvalidity().matches("^\\d{4}$")){                   error.append("ChargeType为信用卡时,信用卡有效期至 格式不正确,");                                   }                if (iterator.next().getChargetype()==3//?    中信信用卡转帐时,Ensuremodel,计划型号必录                    &&iterator.next().getBrushbankcode().equals("017")                    &&iterator.next().getEnsuremodel()==null){                   error.append("中信信用卡转帐时,Ensuremodel,计划型号不能为空");                                                             }


------解决方案--------------------------------------------------------
你应该iterator.next()=一个对象
然后要取什么属性 就取撒 你这样每次都next下 指针每次都向下移动。。。。
  相关解决方案