Hello,

I don't see any errors displayed in Android Studio, but whenever I try to run my application, I get an error message saying that my application has stopped. Here's the source code I have for a spinner:

Main.java

public class HomePage extends AppCompatActivity implements OnItemSelectedListener {

List list;
String [] objects = {"A","B","C","D","E","F"};
ArrayAdapter adapter = new ArrayAdapter (this,
android.R.layout.simple_spinner_item, objects);

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);

Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
spinner.setOnItemSelectedListener(this);
list = new ArrayList(Arrays.asList(objects));

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(adapter);
spinner.setSelection(2);

adapter.notifyDataSetChanged();
}
public void onItemSelected(AdapterView parent, View view,
int pos, long id) {
list.remove(pos);
objects=list.toArray(new String[0]);
adapter.notifyDataSetChanged();
}

public void onNothingSelected(AdapterView parent) {

}


MyAdapter.java

public class MyAdapter extends ArrayAdapter {
Context c;
String[] objects;

public MyAdapter(Context c, int position, String[] objects) {
super(c, position);
this.c = c;
this.objects = objects;
}

@Override
public View getDropDownView(int position, View cnvtView, ViewGroup prnt) {
return getCustomView(position, cnvtView, prnt);
}

@Override
public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}

public View getCustomView(int position, View convertView, ViewGroup parent)

{
LayoutInflater inflater = LayoutInflater.from(c);
View spinner = inflater.inflate(R.layout.custom_spinner, parent, false);
RelativeLayout layout = (RelativeLayout) spinner.findViewById(R.id.layout);
TextView letter = (TextView) spinner.findViewById(R.id.letter);
letter.setText(objects[position]);
if (position == 0) {
layout.setVisibility(View.VISIBLE);
}
return spinner;
}
}