android – 按下按钮加号或减号时的TimePicker空指针异常
作者:互联网
只有当我尝试强制布局显示带有递增和递减按钮的选择器时才会出现问题.因此,当我在我的片段中使用此代码并按“”或“ – ”时,应用程序崩溃:
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.cust_dialog);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
如果我评论上面的代码行,一切正常.
这是cust_dialog:
<style name="cust_dialog" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
这是堆栈跟踪:
09-06 01:15:35.947: E/AndroidRuntime(19858): FATAL EXCEPTION: main
09-06 01:15:35.947: E/AndroidRuntime(19858): java.lang.NullPointerException
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.TimePicker.updateInputState(TimePicker.java:580)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.TimePicker.access$000(TimePicker.java:56)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.TimePicker$2.onValueChange(TimePicker.java:150)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.NumberPicker.notifyChange(NumberPicker.java:1776)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.NumberPicker.setValueInternal(NumberPicker.java:1562)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.NumberPicker.changeValueByOne(NumberPicker.java:1592)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.NumberPicker.access$200(NumberPicker.java:90)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.widget.NumberPicker$1.onClick(NumberPicker.java:633)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.view.View.performClick(View.java:4202)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.view.View$PerformClick.run(View.java:17340)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.os.Handler.handleCallback(Handler.java:725)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.os.Handler.dispatchMessage(Handler.java:92)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.os.Looper.loop(Looper.java:137)
09-06 01:15:35.947: E/AndroidRuntime(19858): at android.app.ActivityThread.main(ActivityThread.java:5039)
09-06 01:15:35.947: E/AndroidRuntime(19858): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 01:15:35.947: E/AndroidRuntime(19858): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 01:15:35.947: E/AndroidRuntime(19858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-06 01:15:35.947: E/AndroidRuntime(19858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-06 01:15:35.947: E/AndroidRuntime(19858): at dalvik.system.NativeStart.main(Native Method)
我该如何解决这个问题?
解决方法:
在timepicker中添加标签.这个对我有用:
<TimePicker android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<requestFocus />
</TimePicker>
参考:http://blog.csdn.net/ljb_blog/article/details/9153435
标签:timepicker,android,nullpointerexception 来源: https://codeday.me/bug/20190825/1719686.html