TimePicker NullPointerException异常的ICS [英] TimePicker NullPointerException on ICS
问题描述
好了,所以我刚换我的 TimePickerDialog
到 TimePicker
控件直接显示在我工作的活动因为客户的需求。
Alright so I just switched my TimePickerDialog
to a TimePicker
widget directly visible in the Activity I'm working on because of customer demand.
现在的问题是,当我preSS任何在所述箭头 TimePicker
,我得到一个NullPointerException异常。
The problem is when I press any of the arrows on said TimePicker
, I get a NullPointerException.
只是为了澄清,没有code什么那么连接到 TimePicker
除了此行的的onCreate()
我的活动方法:
Just to clarify, no code what so ever is attached to the TimePicker
except this line in the onCreate()
method of my Activity:
((TimePicker)findViewById(R.id.time_picker))setIs24HourView(真);
我发现这个帖子在谷歌关于这个问题的论坛,但没有太大的帮助。
I found this post on the Google Forums regarding this issue, but not much help.
这是我的错误日志,我黯然不认为这将是多大的帮助,但。
Here's my error log, I sadly don't think it'll be much help though.
这个问题只在ICS(Android的4.0 +)测试时出现。有没有人能够解决这个问题?
This issue only appears when testing in ICS (Android 4.0 +). Has anyone been able to work around this issue ?
推荐答案
只是写了一个示例应用程序,也没有错误的Galaxy SIII发现(4.0):
Just wrote a sample application and no error found in Galaxy SIII (4.0):
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
public class TimePickerTestActivity extends Activity implements OnTimeChangedListener{
private TimePicker tpTime = null;
private TextView tvTime = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvTime = (TextView)this.findViewById(R.id.tv_time);
tpTime = (TimePicker)this.findViewById(R.id.tp_time);
tpTime.setIs24HourView(Boolean.TRUE);
tpTime.setOnTimeChangedListener(this);
}
public void onTimeChanged(TimePicker tp, final int hrOfDay, final int min) {
if(tp.equals(tpTime)){
tvTime.post(new Runnable(){
public void run() {
tvTime.setText(hrOfDay+":"+min);
}
});
}
}
}
和布局的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TimePicker android:id="@+id/tp_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:id="@+id/tv_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
供参考: http://developer.android.com/reference/android/空间/ TimePicker.html
这篇关于TimePicker NullPointerException异常的ICS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!