调试程序里的NullPointerException
来源:互联网 发布:linux apache ab下载 编辑:程序博客网 时间:2024/05/02 06:32
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
publicstaticvoidvalidateNotNull(finalObjecttestObject)
{
//Ifobjectisnull,thenanexceptionisthrown
if(testObject==null)
{
thrownewIllegalArgumentException("Objectcan'tbenull.");
}
}
如果把它改造成下面的形式,会使输出更加明显:
publicstaticvoidvalidateNotNull(StringobjectName,Objectobject){
if(object==null){
thrownewIllegalArgumentException(objectName+"can'tbenull!!!");
}
}
比如在真正的程序里:
publicvoidcheckLogon(Stringusername,Stringpassword){
Validation.validateNotNull("username",username);
Validation.validateNotNull("password",password);
//...
}
以后,在程序运行的过程中,如果再出现username为null的时候程序就会输出:java.lang.IllegalArgumentException:usernamecan'tbenull!!!
哈哈,再不用为找null犯愁了。养成好的习惯,预防错误的发生,可以节省将来的好多时间。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
XForum的编码规范规定:必须对输入的参数进行null验证用的是Validation里的一个方法,检查对象是否为null:publicstaticvoidvalidateNotNull(finalObjecttestObject)
{
//Ifobjectisnull,thenanexceptionisthrown
if(testObject==null)
{
thrownewIllegalArgumentException("Objectcan'tbenull.");
}
}
如果把它改造成下面的形式,会使输出更加明显:
publicstaticvoidvalidateNotNull(StringobjectName,Objectobject){
if(object==null){
thrownewIllegalArgumentException(objectName+"can'tbenull!!!");
}
}
比如在真正的程序里:
publicvoidcheckLogon(Stringusername,Stringpassword){
Validation.validateNotNull("username",username);
Validation.validateNotNull("password",password);
//...
}
以后,在程序运行的过程中,如果再出现username为null的时候程序就会输出:java.lang.IllegalArgumentException:usernamecan'tbenull!!!
哈哈,再不用为找null犯愁了。养成好的习惯,预防错误的发生,可以节省将来的好多时间。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 调试程序里的NullPointerException
- 有关java.lang.NullPointerException在我的程序里出现的情况
- 利用GDB调试Android里的程序
- eclipse上调试android里的程序。
- 小心!你的代码里有NullPointerException!
- 在SharpDevelop里调试程序
- Eclipse里不能调试J2ME程序的解决办法
- Flex 4.0 在Flex Builder里调试程序的方法
- 在delphi里调试com+程序
- 在调试的时候一定要注意程序里使用的英文单词的细小差别!!
- android启动程序报java.lang.NullPointerException的原因
- 避免Java程序中NullPointerException的技巧和最佳实践
- 避免Java程序中NullPointerException的技巧和最佳实践
- 程序里的天堂
- 开始菜单里的程序
- 调试程序的时候,断点尽量别放在cftransaction里。
- Eclipse里不能调试J2ME程序的解决办法: Attempting to resume current thread
- XCode里插入调试断点,程序却不停止的解决方法
- FuncADDColumn(为表添加字段)
- 令AxosoftPowerTrack支持中文
- 基于IA架构高性能集群系统技术
- 清除冗余记录的SQL语句
- sql学习
- 调试程序里的NullPointerException
- 数据库设计中的14个关键技巧
- RelationAlgebra
- Keys,SuperKeys,PrimaryKeys
- D语言入门---D语言库tango
- 一条SQL语句
- 自建首部曲常用参数功能汇总
- 走出海量数据及访问量压力困境
- 使用时需要经常用到的几个设置选项!