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;"> <TimePicker
            android: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>



你可能感兴趣的:(android,异常,控件)