我正在製作一個使用TimePicker的應用程序,這是我第一次使用它。我的代碼如下:使用Android TimePicker.getCurrentHour的問題
final Dialog mTimeDialog = new Dialog(this);
TimePicker timePicker = (TimePicker)mTimeDialog.findViewById(R.id.timePicker);
TimePicker timePicker1 = (TimePicker)mTimeDialog.findViewById(R.id.timePicker1);
int starthour = timePicker.getCurrentHour();
int startminute = timePicker.getCurrentMinute();
int finishhour = timePicker1.getCurrentHour();
int finishminute = timePicker1.getCurrentMinute();
但我收到一個異常,當我嘗試運行它。當我按保存鍵觸發onClick
,這是包含在,我得到這個:
Caused by: java.lang.NullPointerException
at com.csam.hourtracker.hourentry.onClick(hourentry.java:40)
任何幫助將是巨大的!
什麼是40行'hourentry.java'? – Raghunandan
第40行是int starthour = timePicker.getCurrentHour();對不起,應該已經指定了。 – dacelbot
你的'timePicker'爲空 – Raghunandan