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.
I'm trying to add it to an existing layout programatically
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 thepublic FloatLabeledEditText(Context context)constructor. Hence,mHintTextViewwas never initialized and will cause NPE when it's used inaddView()method.Please help.