Estoy intentando crear un spinner en un menu
Me da error al crear el adapter en el spinner.setAdapter(adapter);
Este es el error que me da
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
MenuItem ite = menu.findItem(R.id.dibujos);
Spinner spinner = (Spinner) ite.getActionView();
SimpleImageArrayAdapter adapter = new SimpleImageArrayAdapter(this, ArrayMinas);
spinner.setAdapter(adapter);
spinner.setOnItemClickListener((AdapterView.OnItemClickListener) this);
return true;
}
public class SimpleImageArrayAdapter extends ArrayAdapter<Integer> {
private Integer[] ArrayMinas;
public SimpleImageArrayAdapter(Context context, Integer[] arrayMinas) {
super(context, android.R.layout.simple_spinner_item);
ArrayMinas = arrayMinas;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getImageForPosition(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getImageForPosition(position);
}
private View getImageForPosition(int position) {
ImageView imageView = new ImageView(getContext());
imageView.setBackgroundResource(ArrayMinas[position]);
imageView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return imageView;
}
}
}