首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Struts2报错InvocationTargetException,传送接口调用

2012-12-25 
Struts2报错InvocationTargetException,传递接口调用。本帖最后由 Javainging 于 2012-12-13 11:19:32 编辑

Struts2报错InvocationTargetException,传递接口调用。
本帖最后由 Javainging 于 2012-12-13 11:19:32 编辑
action代码如下:


private InstReservation instReservation;
private InstrumentReservationService instReservationService;//服务层接口

get、set省略

action中有一个方法调用了工具类如下:
TimeCompute.compute(instReservation,instReservationService);

让静态方法处理。



compute静态方法如下:

public static void compute(InstReservation instReservation,InstReservationService instReservationService) {
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
calendar.setTime(instReservation.getStartTime());
/**
 * 开始时间
 * */
int i = calendar.get(Calendar.DAY_OF_WEEK);// 星期
int j = calendar.get(Calendar.HOUR_OF_DAY);// 小时
int k = calendar.get(Calendar.MINUTE);// 分钟
int l = calendar.get(Calendar.DAY_OF_MONTH);// 日
System.out.println(l + "日、" + "星期" + i + "、" + j + "时、" + k + "分");
Calendar calendar2 = Calendar.getInstance();
calendar.setTime(instReservation.getEndTime());
/**
 * 结束时间
 * */
int m = calendar2.get(Calendar.DAY_OF_WEEK);// 星期
int n = calendar2.get(Calendar.HOUR_OF_DAY);// 时
int o = calendar2.get(Calendar.MINUTE);// 分
int p = calendar2.get(Calendar.DAY_OF_MONTH);// 日
System.out.println(p + "日、" + "星期" + m + "、" + n + "时、" + o + "分");


if (...) {

instReservation.setTimeA("XXX");
instReservationService.update(instReservation);
System.out.println("XXA区间");
System.out.println("XX");
}


额,代码就是这么处理的,不知道为啥页面报错,


java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
.......省略......
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause

java.lang.NoSuchMethodError:
 com.yax.util.TimeCompute.compute(Lcom/yax/entity/InstReservation;Lcom/yax/service/InstReservationService;)V
com.yaxing.action.InstrumentReservationAction.timeCompute(InstrumentReservationAction.java:1043)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)


com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
.......省略......
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Apache Tomcat/6.0.35


另外:java.lang.NoSuchMethodError:
这个异常很奇怪,不知道为啥这样报,而且下面红色加粗的地方,不知道咋多了个L出来了,正常的应该是com/yax/entity/InstReservation而不是
Lcom/yax/entity/InstReservation后面的那个V也不知道啥意思。

谢谢。
[解决办法]
这个是jvm规范中的名称矫直(name mangling)形式,用以区分重载方法

Z: boolean 
B: byte 
C: char 
S: short 
I: int 
J: long 
F: float 
D: double 
L fully-qualified-class-name ; : fully qualified class 
[ type : array of type 
V: void 


不过现在的重点不在这,重点是为什么这个方法com.yax.util.TimeCompute.compute会找不到
这个楼主仔细查一下应该就会清楚

[解决办法]
楼主可以这样,


在Action中,只把instReservation传递过去,


TimeCompute.compute(instReservation);

然后 再回到action中 

  instReservationService.update(instReservation);

不必要传递这个service过去的

热点排行