gpt4 book ai didi

java错误: expected,不知道如何修复

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

我正在筛选一些旧的开源java程序,并试图让它编译和运行。在我的众多错误列表中,有一个是:

java:178: error: <identifier> expected
cons = reflector.getConstructor((Class[])null);
^
java:178: error: cannot find symbol
cons = reflector.getConstructor((Class[])null);
^
symbol: class cons
location: class XMLMapTransformer

有问题的方法是这样的:

private Object unmarshalClass(Class reflector, Node node)
throws InstantiationException, IllegalAccessException,
InvocationTargetException {
Constructor cons = null;
try {
@SuppressWarnings("unchecked")
cons = reflector.getConstructor((Class[])null);
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
return null;
}
Object o = cons.newInstance((Class)null);
Node n;

Method[] methods = reflector.getMethods();
NamedNodeMap nnm = node.getAttributes();

if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
n = nnm.item(i);

try {
int j = reflectFindMethodByName(reflector,
"set" + n.getNodeName());
if (j >= 0) {
reflectInvokeMethod(o,methods[j],
new String [] {n.getNodeValue()});
} else {
logger.warn("Unsupported attribute '" +
n.getNodeName() +
"' on <" + node.getNodeName() + "> tag");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return o;
}

有解决这个问题的想法吗?如果需要,我可以提供更多详细信息或来源链接。

最佳答案

注解可以注解类、成员变量和方法。您不能将它们放入方法主体中 - 这在语法上是不正确的。将注释移至方法上方即可。

关于java错误: <identifier> expected,不知道如何修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33944767/

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