嗨我在運行我的代碼時收到上述錯誤。我無法理解導致錯誤的原因。我已經看到a similar thread上的解決方案,但我不確定這是否適用於我的情況。有人能幫我理解一下嗎?任何幫助是極大的讚賞。異常java.lang.IllegalArgumentException:對象不是在sun上聲明類的實例.reflect.NativeMethodAccessorImpl.invoke0
ERROR
[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;
}
它看起來像你的對象,因爲obj參數不能調用該方法。嘗試使用method.invoke((Object)null,(Object)null);進行調試。回顧發生了什麼。 – DankMemes 2012-08-16 17:27:16
你說你不確定你鏈接的答案適用於你的案例。你能說爲什麼你認爲它可能不適用? – 2012-08-16 21:28:48