SoloCodigo

Programación General => Java => Mensaje iniciado por: luismg69 en Lunes 22 de Enero de 2007, 18:12

Título: No Me Encuentra Metodo Add
Publicado por: luismg69 en Lunes 22 de Enero de 2007, 18:12
public ArrayListSGML<E> extraerFragmentos(Tipo tipo){
   
   ArrayListSGML<E> arrayList=new ArrayListSGML<E>();
   Iterator it=this.iterator();
   while(it.hasNext()){
      FragmentoSGML fragmento=(FragmentoSGML)it.next();
      if(fragmento.darTipo().toString().equals(tipo.toString()))
           arrayList.add(fragmento);<------
      }
      return arrayList;
   }

En el constructor de la clase donde esta el metodo, pone:

public class ArrayListSGML<E extends FragmentoSGML> extends ArrayList<E>


Entonces, por qué no me deja añadir un fragmento a arrayList??
el error q me sale en compilacion es el siguiente:

C:\practica2\src\ubu\lsi\mepro\sgml\ArrayListSGML.java:51: cannot find symbol
symbol  : method add(ubu.lsi.mepro.sgml.FragmentoSGML)
location: class ubu.lsi.mepro.sgml.ArrayListSGML<E>
                          arrayList.add((FragmentoSGML)fragmento);


Decir que tengo importado el java.util.*; para el tratamiento de arrayList.

Gracias
Título: Re: No Me Encuentra Metodo Add
Publicado por: chuidiang en Martes 23 de Enero de 2007, 07:08
Hola:

Revisa el tema de los genéricos, templates o plantillas, como quieras llamarlos. Es posible que no hayas instanciado o no lo tengas bien para que admita un add() cuyo tipo de parámetro sea FragmentoSGML

En algún sitio debes instanciar así

 ArrayListSGML<FragmentoSGML> arrayList = new ArrayListSGML<FragmentoSGML>();

o la clase que sea.

Se bueno.