-
Notifications
You must be signed in to change notification settings - Fork 219
Open
Description
I'm trying to add it to an existing layout programatically
private void addEditText(){
EditText itemText = new EditText(getActivity());
itemText.setHint(R.string.add_item);
itemText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
FloatLabeledEditText floatLabeledEditText = new FloatLabeledEditText(getActivity());
floatLabeledEditText.addView(itemText);
mItemParent.addView(floatLabeledEditText);
}But I got NPE when I do that:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float android.widget.TextView.getTextSize()' on a null object reference at com.wrapp.floatlabelededittext.FloatLabeledEditText.addView(FloatLabeledEditText.java:106)
Because setAttributes() was not called in the public FloatLabeledEditText(Context context) constructor. Hence, mHintTextView was never initialized and will cause NPE when it's used in addView() method.
Please help.
Metadata
Metadata
Assignees
Labels
No labels