int 上出现 NullPointerException?
有谁可以帮助我解决这个问题...
我的代码: http://pastebin.com/eD2WknXA
崩溃在第 178 行带有 NPE 的
数组所在类的构造函数中,我什至放置了一个将所有整数设置为 0 的代码块,但即使这样也没有帮助?
有人吗?
is there anyone who can help me with this...
My code: http://pastebin.com/eD2WknXA
Crashes at the line 178 with a NPE
In the constructor of the class which the array is in, I even put a block of code which sets all the integers to 0, but even this didnt help?
anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您很可能拥有
Integer[]
,其Integer
元素为null
(自动拆箱)int[]
,它本身就是null
。编辑:
从您粘贴的代码来看,它只能是数组
cur
本身,即null
。root
不能为null
,因为这样 NPE 将位于上一行You are very likely to have either
Integer[]
with anInteger
element beingnull
(auto-unboxing)int[]
, which isnull
itself.EDIT:
From your pasted code, it can only be the array
cur
itself, which isnull
.root
cannot benull
, because then the NPE would be on the previous line您确定它在某些时候没有使用
Integer
并自动拆箱为 int 吗?例如:Are you sure it's not using an
Integer
at some point, and auto-unboxing to int? For example:这是第 178 行:
因此,要么 root 为 null,要么 root.n 为 null,要么 cur 为 null。放入一些调试语句来检查这些引用的值或在调试器中观察它们。
Here is line 178:
So either root is null, root.n is null or cur is null. Put some debugging statements in to check the value of these references or watch them in a debugger.
难道你的int数组(里面没有任何元素)是null吗?
Can it be that your int array (not any element inside) is null?