I'm trying to make a TextView programmatically in a LinearLayout. The program includes a checking system to check if its been added already and the prompt for creating the textview is an option in a spinner. Here is the full onClick method for the spinner
public void onClick(String Ingredient, int i) {
Toast.makeText(Kitchen.super.getContext(), "Selected "+Ingredient, Toast.LENGTH_SHORT).show();
if(Ingredient.equals(tomatoSauce.name)) {
if (tomatoSauce.init == 0){
tomatoSauce.init = 1;
TextView one = new TextView(getContext());
one.setText(Ingredient);
mainll.addView(one);
}
} else if(Ingredient.equals(chicken.name)) {
chicken.init = 1;
} else if(Ingredient.equals(olives.name)){
olives.init = 1;
}
}
The Linear layout is identified from the xml layout when the app is started in a separate method.
final LinearLayout mainll = (LinearLayout) getActivity().findViewById(R.id.main);
The app crashes upon selecting Tomato Sauce from the menu despite the lack of identified coding errors. Any help with this issue would be greatly appreciated.