在我的项目中,我使用了这个库,一个 DatePickerDialog,以及 HoloEverywhere 和其他一些次要的视图库。我的问题是,当我尝试仅在 2.3.3 设备上创建此对话框时,我得到了 NullPointerException 。
然而,奇怪的是,当我使用这个库并在其他项目(例如 HoloEverywhere 演示)中使用完全相同的代码创建对话框时,它可以在所有设备上完美运行。我正在 (HoloEverywhere) Activity 的 onClick 方法中使用以下代码创建 DatePickerDialog:
final DatePickerDialog dpd = DatePickerDialog.newInstance(this, 2013, 5, 16, false);
dpd.setYearRange(2013, 2015);
dpd.show(getSupportFragmentManager(), "datepicker");
这给了我以下错误:
08-19 20:55:45.434: E/AndroidRuntime(1330): FATAL EXCEPTION: main
08-19 20:55:45.434: E/AndroidRuntime(1330): java.lang.NullPointerException
08-19 20:55:45.434: E/AndroidRuntime(1330): at com.fourmob.datetimepicker.date.DatePickerDialog.onCreateView(DatePickerDialog.java:203)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.os.Handler.handleCallback(Handler.java:587)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.os.Looper.loop(Looper.java:130)
08-19 20:55:45.434: E/AndroidRuntime(1330): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-19 20:55:45.434: E/AndroidRuntime(1330): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 20:55:45.434: E/AndroidRuntime(1330): at java.lang.reflect.Method.invoke(Method.java:507)
08-19 20:55:45.434: E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-19 20:55:45.434: E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-19 20:55:45.434: E/AndroidRuntime(1330): at dalvik.system.NativeStart.main(Native Method)
堆栈跟踪中提到的类/行可以在这里找到
希望这是足够的信息。干杯,伙计们。