Class Cast exception error: trying to write the into the file

I am trying to export the file but an getting the following exception:

An unexpected error occurred: java.lang.Exception: The application script threw an exception: java.lang.ClassCastException: Cannot cast to java.lang.String BSF info: Export File - Abc at line: 0 column: columnNo

Mi código está abajo:


    String appname = "Abc";
    String path = "//home/exportfile//";
    String filename = path+"ApplicationExport-"+appname+".txt";
    String ret = "false";

    QueryOptions ops = new QueryOptions();
    Filter [] filters = new Filter[1];
    filters[0] = Filter.eq("", appname);

    List props = new ArrayList();

    //Do search
    Iterator it =, ops, props);

    //Build file and export header row
    BufferedWriter out = new BufferedWriter(new FileWriter(filename));

    //Iterate Search Results
    if (it!=null)
            while ( it.hasNext() ) {
                    //Get link and create object
                    Object [] record =;
                    String identityName = (String) record[0];
                    Identity user = (Identity) context.getObject(Identity.class, identityName);

                    //Get Identity attributes for export
                    String workforceid = (String) user.getAttribute("workforceID");                 

                    //Get application attributes for export
                    String userid="";
                      String org="";
                    List links = user.getLinks();
                    if (links!=null)
                            Iterator lit = links.iterator();
                            while (lit.hasNext())
                                    Link l =;
                                    String lname = l.getApplicationName();
                                    if (lname.equalsIgnoreCase(appname))
                                              userid = (String) l.getAttribute("User Name");
                                              org= (String) l.getAttribute("Organization");

                    //Output file
    //Close file and return
    return ret;     

While running the above code i am getting the cast exception error: since the Organization attribute is Multivalued.i.e.: in that attribute you can have more than one value.

any help to correct this code would be greatly appreciated.

preguntado el 31 de julio de 12 a las 14:07

1 Respuestas

It says it clearly, you are getting an object of type and trying to cast it to a string.

From your question i understand the problem is here:

org= (String) l.getAttribute("Organization");

Entonces necesitas cambiarlo a: orgList = ( l.getAttribute("Organization");

and then extract the correct value from that list.

Respondido 31 Jul 12, 14:07

Changing the above values didnt help.. do you recommend using List or ArrayList for that attribute? I am very new to no clue where to change this code? - user1565893

The code ran without error.but it didnt write anything in Organization column. - user1565893

so that means it sí logró work. now you have a different problem. you can update the question with the new code and describe the new problem. - Tomer

Do you recommend anything why it the code didnt wrote anything in File? - user1565893

update the question with the new code and explain exactly what is the new problem. - Tomer

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.