我有以下内容并且出现了以下错误:
java.lang.String无法转换为[Ljava.lang.String;
我将Object[]
更改为String[]
,因为我遇到了下一个错误:
java.lang.Object无法转换为[Ljava.lang.String;
有什么想法吗?
private Collection queryStatement(String SelectStatement) {
int colcount = 0;
int rowcount = 0;
int rowcounter = 0;
ArrayList a = new ArrayList();
Query query = getEntityManager().createNativeQuery(SelectStatement);
List<String[]> resultList = (List<String[]>) query.getResultList();
if (!resultList.equals(Collections.emptyList())) {
rowcount = resultList.size();
}
if (rowcount > 0) {
colcount = ((String[]) query.getResultList().get(0)).length;
}
rows = rowcount;
cols = colcount;
String[][] array = new String[rowcount][colcount];
for (String[] obj : resultList) {
String[] record = new String[colcount];
for (int colCounter = 0; colCounter < colcount; colCounter++) {
record[colCounter] = safeValue(obj[colCounter]+"");
}
array[ rowcounter++] = (String[]) record;
}
a.add(array);
return a;
}
List<String[]>
?看起来应该返回一个List<String>
,因此出现了错误。 - Jorn VerneeList<String[]>
而不是将其视为可能性之一。 - Marko Topolnik