• Domingo 22 de Septiembre de 2024, 01:08

Autor Tema:  No Me Encuentra Metodo Add  (Leído 910 veces)

luismg69

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
No Me Encuentra Metodo Add
« en: Lunes 22 de Enero de 2007, 18:12 »
0
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

chuidiang

  • Miembro MUY activo
  • ***
  • Mensajes: 123
  • Nacionalidad: es
    • Ver Perfil
    • http://www.chuidiang.com
Re: No Me Encuentra Metodo Add
« Respuesta #1 en: Martes 23 de Enero de 2007, 07:08 »
0
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.