即使Java不支持指针,但Java为什么会抛出java.lang.NullPointerException: [英] EvenThough Java Does not Support Pointers But Why Java Throws java.lang.NullPointerException:
本文介绍了即使Java不支持指针,但Java为什么会抛出java.lang.NullPointerException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么会这样Bcz我已经多次遇到此异常....
I Want To Know Why This happens Bcz i Have Faced This Exception So many Times....
推荐答案
原因很多.请参考- NullPointerException类 [
There are many reasons. Refer - Class NullPointerException[^].
报价:
当应用程序尝试在
中使用
中使用
null
时抛出
需要对象的情况.其中包括:- 调用
null
对象的实例方法.
- 访问或修改
null
对象的字段.
- 以
null
的长度作为数组.
- 访问或修改
null
的插槽,就像它一样
是一个数组.
- 将
null
视为Throwable
值.
Thrown when an application attempts to use
case where an object is required. These include:
null
in acase where an object is required. These include:
- Calling the instance method of a
null
object.
- Accessing or modifying the field of a
null
object.
- Taking the length of
null
as if it were an array.
- Accessing or modifying the slots of
null
as if it
were an array.
- Throwing
null
as if it were aThrowable
value.
应用程序应抛出此类的实例以指示
null
对象的其他非法使用. NullPointerException
对象可以由虚拟机构造,就像
Applications should throw instances of this class to indicate
other illegal uses of the null
object. NullPointerException
objects may be constructed by the virtual machine as if suppression were disabled and/or the
stack trace was not writable.
这篇关于即使Java不支持指针,但Java为什么会抛出java.lang.NullPointerException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文