当我在XML文件中添加文本输入布局时,但是当我单击日期选择器类应用程序时,应用程序崩溃了



我正在对材料设计(使用textInputlayout)进行诚意。

Attempt to invoke virtual method 'int android.widget.NumberPicker.getChildCount()' on a null object reference 

我的gradle文件如下

apply plugin: 'com.android.application'

我不明白,删除textInputlayout解决了问题...

注意:我在清单中定义了 Theme.AppCompat.Light

您的 NumberPicker是null,它不是初始化的,或者如果您使用了 findViewById,则尚未找到它,因此,在null对象上调用 getChildCount会抛出nullpoInterExcept。

尝试解析NumberPicker参考并确保其不是null并在您的视图/活动/片段中找到的。

尝试调用虚拟方法'int android.widget.numberpicker.getChildCount()'在空对象上 参考

从中,您可以看到异常是NullPoInterException。它说,getChildCount()方法在空点上被调用。这意味着,NumberPicker类型的对象为null。

因此,如果您已经初始化了对象,请检查代码的初始化部分。如果在XML文件中找不到ID,则您的FindViewByID也可能无法正常工作。

最新更新