Please i have a for loop which creates edittext according to what the user types in. It displays the edittexts in a linearlayout. What i want to do is to get each of the texts from the edittexts and store it in an arraylist
This is the for loop.
for (i = 0; i < length; i++) {
editText = new EditText(MainActivity.this);
editText.setId(i + 1);
editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
editText.setText("Input" + " " + (i + 1));
listLayout.addView(editText);
editTextCollection.add(editText);
}
I tried adding each editTexts to the ArrayList
editTextCollection but i keep getting an error
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
1 Answer(s)