嗨,我在运行代码时收到上述错误。我无法理解导致错误的原因。我在类似的线程上看到了解决方案,但我不确定这是否适用于我的情况。有人可以帮我理解一下吗?任何帮助是极大的赞赏。
错误
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/window].[jsp]]
Servlet.service() for servlet jsp threw exception
java.lang.IllegalArgumentException: object is not an instance of
declaring class at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
com.container.taglib.util.MirrorMaker.invokeMethod(MirrorMaker.java:54)
at
com.container.taglib.util.MirrorMaker.invokeMethod(MirrorMaker.java:48)
at
com.container.taglib.list.TableSorter.invokeMethod(TableSorter.java:1092)
at
com.container.taglib.list.TableSorter.createList(TableSorter.java:503)
at
com.container.taglib.list.TableSorter.doAfterBody(TableSorter.java:151)
代码:
public static Object invokeMethod(Object obj, Method method, Object[] params)throws IllegalAccessException, InvocationTargetException{
Object ret = null;
String str = "";
try{
ret = method.invoke(obj, params);
if(ret instanceof String){
str = (String)ret;
//logger.info("ret str: "+str);
}else if(ret instanceof Integer){
str = ((Integer)ret).toString();
//logger.info("ret int: "+str);
}else if(ret instanceof java.util.Date){
str = new SimpleDateFormat("yyyy-MM-dd").format(ret);
logger.info("ret date: "+str);
}else if(ret instanceof Double) {
str = ((Double)ret).toString();
}else if(ret instanceof ArrayList){
return ret;
}else{
return ret;
}
}catch(IllegalAccessException ex){
logger.info("illegal access");
throw ex;
}catch(InvocationTargetException ex){
logger.error("invocation target ex");
throw ex;
}
return str;
}