我知道getView()可能会在onCreateView()方法内部返回null ,但即使我将下面的代码放在里面onActivityCreated(),onStart()或者onViewCreated()方法,它仍然会NullPointerException在Android Studio中显示有关可能的警告(尽管我的程序运行没有任何问题).如何摆脱这种警告?
我正在使用碎片.
码:
datpurchased = (EditText) getView().findViewById(R.id.datepurchased);
//datpurchased defined as instance variable in the class
Run Code Online (Sandbox Code Playgroud)
警告:
方法调用'getView().findViewById(R.id.datepurchased)'可能会产生'java.lang.NullPointerException'