android之单元测试问题汇总

来源:互联网 发布:c语言sqrt是什么意思 编辑:程序博客网 时间:2024/06/14 23:11

问题1:

Can't create handler inside thread that has not called Looper.prepare()

解决1:

 Looper.prepare();


问题2:

getMainLooper()' on a null object reference

解决2:

 Looper.getMainLooper()
问题3:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
解决3:
对这种情况一定要先判断是否为空,如果不为空再做强转
Integer tmp;
...
if(tmp) != null) {    setValue(tmp.intValue());}

问题4:Actually, there were zero interactions with this mock.