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

java.lang.reflect.InvocationTargetException 错误解决办法

2012-11-03 
java.lang.reflect.InvocationTargetException 异常解决方法!点击下面标题查看本文完整版:java.lang.refle

java.lang.reflect.InvocationTargetException 异常解决方法!
点击下面标题查看本文完整版:java.lang.reflect.InvocationTargetException 异常解决方法!


大家帮看一下,一个小错误。 java.lang.reflect.InvocationTargetException
public static String getTdZd(HttpServletRequest request,String lbxx)
{
XinxiProperty a = null; ? String s1 = "";
HttpSession mySession = request.getSession();
ServletContext application = mySession.getServletContext();
List l= (List)application.getAttribute("xinxiPropertyList");
if (l!=null){
? for (int i=0;i < l.size() ;i ++)
? {

? a =(XinxiProperty)l.get(i);
? if (a.getXxlb().equals(lbxx)==true){
//A点? 到这里出错
? s1= a.getTd().toString();
? return "1" ;
? }
? }
}
return "" ;


//XinxiProperty 类
public class XinxiProperty {
public String td,xxlb;

public String getTdjs() {
return tdjs;
}
public void setTdjs(String tdjs) {
this.tdjs = tdjs;
}
public String getXxlb() {
return xxlb;
}
public void setXxlb(String xxlb) {
this.xxlb = xxlb;
}

//这里a.td为空
a.xxlb 有值
a.td? = null


//A点 调试到的错误
public InvocationTargetException(Throwable target) {
super((Throwable)null);?
this.target = target;
}

------解决方法--------------------
InvocationTargetException 是一种包装由调用方法或构造方法所抛出异常的受查异常
------解决方法--------------------
在进行Java开发的时候很少会接触到这个异常,不过在进行Eclipse插件开发中则不同,很多API都声明抛出此类异常,因此必须对此异常进行处理。

------解决方法--------------------
可以写一个方法统一处理下:
?

Java code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> private static void handleException(Exception e) {  MessageDialog.openError(Activator.getDefault().getWorkbench()   .getDisplay().getActiveShell(), "error", e.getMessage());  e.printStackTrace(); }
    

热点排行