Error java.lang.ClassCastException: java.lang.String; can not be cast

0

I do not understand why the error, please help.

public ArrayList EvaluarPatronFiguras(Image Imagen)
{
    ArrayList ListaResultadoRegiones = new ArrayList();
    aImagen=Imagen;
    //convirtiendo imagen a matriz
    CmatrizTransformacion oTransformador=new CmatrizTransformacion();
    String[][] MatrizImagen=oTransformador.ObtenerMatrizPatron(aImagen);

    CConversion conversor = new CConversion();
    BufferedImage imagenB = conversor.Convertir_Buffer(aImagen);

    oTransformador.Graficar(MatrizImagen);
    //obtener la lista de subregiones
    CAgrupar oGenerarGrup=new CAgrupar();
    ArrayList ListaGrupos = oGenerarGrup.GererarListaGrupos(MatrizImagen, "1");

    //evaluar Cada region dela figura
    int NroRegiones = ListaGrupos.size();
    for(int i=0;i<NroRegiones;i++)
    {

       CRegion SubRegioni;
       SubRegioni = (CRegion) ListaGrupos.get(i);


        double[] Resultadoi=EvaluarRegionFiguraPatron(SubRegioni.getaRegion());
        ListaResultadoRegiones.add(Resultadoi);

        ConstruirImagen(imagenB, SubRegioni.getaPosIx(), SubRegioni.getaPosIy(), SubRegioni.getaPosFx(), SubRegioni.getaPosFy());
    }
    return ListaResultadoRegiones;

}

The line that gives me error is the one that says SubRegioni = (CRegion) ListaGrupos.get (i);

    
asked by Jeisson Hernandez 24.08.2017 в 02:05
source

2 answers

2

You might have a problem with the type defined for GroupList, check that:

ArrayList ListaGrupos = oGenerarGrup.GererarListaGrupos(MatrizImagen, "1");

It should be:

 ArrayList<CRegion> ListaGrupos = oGenerarGrup.GererarListaGrupos(MatrizImagen, "1");

And the function "oGenerarGrup.GererarListaGrupos":

function ArrayList<CRegion> GererarListaGrupos(....){
    ....
}
    
answered by 24.08.2017 в 02:43
0

1) I do not know what the method or GenerateGroup.GererateListGroups (..) does, but you should analyze the return of that method to see if there are any errors.

2) The CRegion class is an object that does not know what attributes it has, it may only have one however GangList.get (i) is returning a String not something that can be mapped as a CRegion.java.

3) I just realized that MatrixImage is a String [] [] and the method orTransformer.Graficar (MatrixImage) may not be working correctly.

I think the question is still very open, there may be many reasons that throw that error but basically you are saying that the String GroupList.get (i) can not be cast as a CRegion.java

    
answered by 24.08.2017 в 02:59