首页 > 解决方案 > 当我将文本输入布局添加到我的 xml 文件时,它的工作但当我单击日期选择器类应用程序崩溃时

问题描述

我正在将我的编辑文本制作为材料设计(使用 TextInputLayout)。它工作正常。但是当我点击我的 DatePicker 时,应用程序崩溃说:

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在清单中定义

标签: android

解决方案


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

From this, you can see that the exception is a NullPointerException. and it says that, getChildCount() method was called on a null point. Which means that, the object of type NumberPicker is null.

So, if you've initialized the object, please check the initialization part of your code. And your findViewById might be also not working as well if the ID wasn't found in the XML file.


推荐阅读