Android NullPointerException-调试特定行 [英] Android NullPointerException - Debugging a specific line

查看:37
本文介绍了Android NullPointerException-调试特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样一行:

var.getSomething().getSomethingElse().setNewValue(stuff.getValue().getWhatever());

如果该行创建了 NullPointerException ,是否有办法找出哪个方法返回了 null 值?

If that line creates a NullPointerException, is there any way of finding out which method is returning a null value?

我相信我能够在每个点处分割线并得到显示哪条线出现故障的异常.但是我无法继续工作(也许我记错了).

I believe I was able to split the line at every dot and get the exception showing which line was failing. But I can't get that to work anymore (maybe I remember incorrectly).

这样写是唯一好的调试可能性吗?

Is the only good debugging possibility to write it like this?

a = var.getSomething();
b = a.getSomehingElse();
c = stuff.getValue();
d = c.getWhatever();
b.setNewValue(d);

有了这个,我应该能够轻松地看到异常发生的地方.但是用这种方式写起来感觉效率低下而且很丑.

With this I should be able to easily see where the exception happens. But it feels inefficient and ugly to write this way.

我使用Android Studio.以前使用过Eclipse,但不久前移到了Android Studio.

I use Android Studio. Used Eclipse before but moved to Android Studio some time ago.

推荐答案

您可能希望将每个零件放入手表"中:

You might want to put every part into "Watches":

但是我很确定Eclipse和Android Studio都可以让您仅通过选择感兴趣的部分(如果处于调试模式)来检查内容

But I'm pretty sure that both Eclipse and Android Studio would let you inspect the content by just a selection of the part you' re interested in (if you are in debug mode)

这篇关于Android NullPointerException-调试特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆