我有以下代码:
1) 从膨胀的 EditText 读取值并将其存储在 ArrayList 中的方法
private List<String> getDynEditText(LinearLayout parentLayout, int resourceId) {
List<String> contactDataList = new ArrayList<String>();
int dataSize = (parentLayout.getChildCount() != 0 ) ? parentLayout.getChildCount() : 0;
for (int i=0; i<dataSize;i++) {
EditText editText = (EditText) parentLayout.getChildAt(i).findViewById(resourceId);
String editString = editText.getText().toString();
if (editString != null && !editString.trim.equals("")) {
contactDataList.add(editString);
}
}
2)我在其他地方调用这个方法
mcontactList.addAll(getDynEditText(mPhoneNumberLinearLayout,
R.id.dy_phone_number_edit_text_id));
问题 :
java.lang.NullPointerException
at.dyn.edt.contacts.ContactActivityDemo.getDynEditText(....)
如果我点击它,它会在该行显示错误
int dataSize = (parentLayout.getChildCount() != 0) ? parentLayout.getChildCount() : 0;
请有人帮帮我吗?