recherche

Maison  >  Questions et réponses  >  le corps du texte

java如何存储list数据?

我想从数据库中取出一组数据保存到List中,然后根据我自己的业务处理之后,再把该List保存到另一个List中去,比如说arlist..应该如何操作?

以下是我的代码。。但是报错了。

private List<TPhoneAttribute> temp;
private PhoneAttributeService PhoneAttributeService;
List listResult = null;
for(int i =0;i < attrList.size();++i){
            temp = PhoneAttributeService.sortByGoodsId(attrList.get(i).getType(), attrList.get(i).getGoodsId());
            listResult.add(temp);
        }
        

报错如下:
java.util.ArrayList cannot be cast to com.ones.domain.TPhoneAttribute..

我猜应该是类型不匹配。。请问如何才能达到我以上所描述的情况?

PHPzPHPz2893 Il y a quelques jours439

répondre à tous(3)je répondrai

  • 大家讲道理

    大家讲道理2017-04-17 18:03:21

    Collections.copy()

    répondre
    0
  • PHP中文网

    PHP中文网2017-04-17 18:03:21

    cannot be cast to  这个已经给出了你,一个错误提示。就是类型转换错误。你把一个A类型的数据转换成B类型,也没有做强制转换处理,A类和B类也没有直接或者间接的集成关系,因此会抛异常啊。

    répondre
    0
  • PHP中文网

    PHP中文网2017-04-17 18:03:21

    Le type de

    listResult est incorrect et votre listResult n'a pas encore été initialisé. L'appel direct de la méthode add() signalera une exception de pointeur nul, elle devrait donc être

    .
    //或者其他List
    List<List<TPhoneAttribute>> listResult = new ArrayList<>();

    répondre
    0
  • Annulerrépondre