本文主要是介绍TimePicker点击上下方向键 java.lang.NullPointerException异常,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天做应用时用到 TimePicker控件。
很意外,点击上下选择键,竟然出错了。
<span style="font-size:14px;">02-25 20:06:38.365: E/AndroidRuntime(2990): FATAL EXCEPTION: main
02-25 20:06:38.365: E/AndroidRuntime(2990): java.lang.NullPointerException
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.TimePicker.updateInputState(TimePicker.java:586)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.TimePicker.access$000(TimePicker.java:60)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.TimePicker$3.onValueChange(TimePicker.java:182)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.NumberPicker.notifyChange(NumberPicker.java:1750)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.NumberPicker.setValueInternal(NumberPicker.java:1536)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.NumberPicker.changeValueByOne(NumberPicker.java:1564)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.NumberPicker.access$200(NumberPicker.java:88)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.widget.NumberPicker$2.onClick(NumberPicker.java:606)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.view.View.performClick(View.java:4147)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.view.View$PerformClick.run(View.java:17161)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.os.Handler.handleCallback(Handler.java:615)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.os.Handler.dispatchMessage(Handler.java:92)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.os.Looper.loop(Looper.java:213)
02-25 20:06:38.365: E/AndroidRuntime(2990): at android.app.ActivityThread.main(ActivityThread.java:4787)
02-25 20:06:38.365: E/AndroidRuntime(2990): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 20:06:38.365: E/AndroidRuntime(2990): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 20:06:38.365: E/AndroidRuntime(2990): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-25 20:06:38.365: E/AndroidRuntime(2990): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-25 20:06:38.365: E/AndroidRuntime(2990): at dalvik.system.NativeStart.main(Native Method)</span>
原来,TimePicker控件里面要加个requeset参数
如下,就可以解决问题了:
<span style="font-size:14px;"> <TimePickerandroid:id="@+id/arrange_time"android:layout_marginTop="10dp"android:layout_gravity="center_horizontal"android:layout_width="wrap_content"android:layout_height="wrap_content"><requestFocus/> </TimePicker></span>
这篇关于TimePicker点击上下方向键 java.lang.NullPointerException异常的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!