在更改时间时强制关闭:时间选择器 (NPE) [英] Force Close on Changing time: Time Picker (NPE)
问题描述
当我点击时间选择器更改时间时,我强制关闭.
When I click on the time picker for changing the time I get force close.
谁能告诉我代码中的问题在哪里.安卓.这是我的代码......
Can anybody tell me where is the problem in my code. Android. and this is my code......
timePickerDateTimePickerPopup = (TimePicker) layoutDateTimePickerPopup.findViewById(R.id.timePicker_datetimepicker);
timePickerDateTimePickerPopup.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
timePickerDateTimePickerPopup.setIs24HourView(true);
timePickerDateTimePickerPopup.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY));
timePickerDateTimePickerPopup.setCurrentMinute(mCalendar.get(Calendar.MINUTE));
timePickerDateTimePickerPopup.setOnTimeChangedListener(this);
dateTimePickerPopup.setTouchable(true);
dateTimePickerPopup.setFocusable(true);
dateTimePickerPopup.setOutsideTouchable(true);
Drawable image_saved = context.getResources().getDrawable(R.drawable.dummy_bg);
dateTimePickerPopup.setBackgroundDrawable(image_saved);
我的 Logcat 显示 NullPointerException:
My Logcat shows a NullPointerException:
STACK_TRACE=java.lang.NullPointerException
at android.widget.TimePicker.updateInputState(TimePicker.java:553)
at android.widget.TimePicker.access$000(TimePicker.java:55)
at android.widget.TimePicker$2.onValueChange(TimePicker.java:149)
at android.widget.NumberPicker.notifyChange(NumberPicker.java:1777)
at android.widget.NumberPicker.changeCurrent(NumberPicker.java:1455)
at android.widget.NumberPicker.changeCurrentByOne(NumberPicker.java:1481)
at android.widget.NumberPicker.access$100(NumberPicker.java:70)
at android.widget.NumberPicker$2.onClick(NumberPicker.java:592)
at android.view.View.performClick(View.java:3519)
at android.view.View$PerformClick.run(View.java:14140)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
推荐答案
在我的 AndroidManifest.xml
中将我的应用程序的主题更改为 android:Theme.Black
.为我解决了问题.
Changing the theme of my application to android:Theme.Black
in my AndroidManifest.xml
. solved the problem for me.
将此样式添加到 styles.xml
我的片段的样式看起来不同,但现在可以使用了.
The style of my fragment looks different but now it works.
更新:我在不改变样式的情况下解决了这个问题,添加了属性 android:descendantFocusability="blocksDescendants"
到我的时间选择器
Update:
I have fixed this issue without changing the style, adding the property android:descendantFocusability="blocksDescendants"
to my TimePicker
<TimePicker
android:id="@+id/toTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants" />
这篇关于在更改时间时强制关闭:时间选择器 (NPE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!