浏览 1798 次
锁定老帖子 主题:NullPointerException
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-05-12
最后修改:2009-05-12
* 调用 null 对象的实例方法。 例如一个String类型的变量str 我们没有其进行赋初始值,默认为null,此时如果我们调str.equals("quit")时就会抛出 NullPointerException异常.如果我们换一个方式"quit".equals(str)则可以避免NullPointerException异常. * 访问或修改 null 对象的字段。 * 将 null 作为一个数组,获得其长度。 String str[] = null; System.out.println(str.length); * 将 null 作为一个数组,访问或修改其位置。 String str[] =null; System.out.println(str[0]); * 将 null 作为 Throwable 值抛出。 throw null; 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |