从 TimePicker 使用 setCurrentMinute(Integer currentMinute) 时出现 NullPointerException
public void onTimeChanged(TimePicker tp, int hour, int min){
tp.setOnTimeChangedListener(null);
Integer a = new Integer(5);
if(a == null){
Log.d("ff", "integer IS null");
} else {
Log.d("ff", "integer is NOT null");
}
if(tp == null){
Log.d("ff", "tp IS null");
} else {
Log.d("ff", "tp is NOT null");
}
tp.setCurrentMinute(a);
tp.setOnTimeChangedListener(this);
}
这是我的TimePicker#OnTimeChangedListener
。 tp.setCurrentMinute(a)
导致 NullPointerException
。我尝试过使用 int 和 Integer - 都不起作用。 tp 不为空,a 也不为空。 在模拟器上工作得很好,但在运行 2.2 的手机上却不行。
public void onTimeChanged(TimePicker tp, int hour, int min){
tp.setOnTimeChangedListener(null);
Integer a = new Integer(5);
if(a == null){
Log.d("ff", "integer IS null");
} else {
Log.d("ff", "integer is NOT null");
}
if(tp == null){
Log.d("ff", "tp IS null");
} else {
Log.d("ff", "tp is NOT null");
}
tp.setCurrentMinute(a);
tp.setOnTimeChangedListener(this);
}
This is my TimePicker#OnTimeChangedListener
. tp.setCurrentMinute(a)
causes a NullPointerException
. I've tried using an int and an Integer - neither works. tp is not null and a isn't either.
Works just fine on emulator, but not on phone running 2.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文档中:
您将侦听器设置为 null,然后当您调用 .setCurrentMinute(a) 时,TimePicker 在尝试通知 null 侦听器时给出 NullPointerException
From the documentation:
You are setting the listener to null, then when you invoke .setCurrentMinute(a) the TimePicker gives a NullPointerException while trying to notify a null listener