gpt4 book ai didi

java - 类转换异常错误: trying to write the into the file

转载 作者:行者123 更新时间:2023-12-01 15:15:02 25 4
gpt4 key购买 nike

我正在尝试导出文件,但出现以下异常:

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

我的代码如下:

    import java.io.FileWriter;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;

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("application.name", appname);
ops.add(filters);

List props = new ArrayList();
props.add("identity.name");

//Do search
Iterator it = context.search(Link.class, ops, props);

//Build file and export header row
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write("IdentityName,UserName,WorkforceID,Organization");
out.newLine();

//Iterate Search Results
if (it!=null)
{
while ( it.hasNext() ) {
//Get link and create object
Object [] record = it.next();
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 = lit.next();
String lname = l.getApplicationName();
if (lname.equalsIgnoreCase(appname))
{
userid = (String) l.getAttribute("User Name");
org= (String) l.getAttribute("Organization");
}
}
}

//Output file
out.write(identityName+","+userid+","+workforceid+","+org);
out.newLine();
out.flush();
}
ret="true";
}
//Close file and return
out.close();
return ret;

运行上述代码时,我收到强制转换异常错误:因为组织属性是多值的,即:在该属性中,您可以有多个值。

任何纠正此代码的帮助将不胜感激。

最佳答案

它清楚地表明,您正在获取一个 sailpoint.tools.xml.PersistentArrayList 类型的对象并尝试将其转换为字符串。

根据您的问题,我了解到问题出在这里:

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

所以你需要将其更改为:

sailpoint.tools.xml.PersistentArrayList orgList = (sailpoint.tools.xml.PersistentArrayList) l.getAttribute("Organization");

然后从该列表中提取正确的值。

关于java - 类转换异常错误: trying to write the into the file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11741553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com