Buggy code:
public class MainActivity extends ActionBarActivity implements CalendarFragment . CalendarListener , CashGestureFragment . CashGestureListener , StudentListFragment . StudentListListener { private static final int ADD_STUDENT_CODE = 9 ; private static final int DETAILS_STUDENT_CODE = 10 ; private static final String STUDENT_EXTRA = "student" ; private Toolbar toolbar ; private ViewPager pager ; private TabAdapter tabAdapter ; private SlidingTabLayout tabs ; private Intent addStudentIntent ; private Intent detailsStudentIntent ; private List < Student > studentsPayment ; private List < Lesson > lessonsPayment ; @ Override protected void onCreate ( Bundle savedInstanceState ) { } @ Override protected void onPostResume ( ) { } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { } @ Override public void addNewStudent ( ) { } @ Override public void detailsStudent ( Student s ) { } @ Override protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { } @ Override public List < Lesson > getLessons ( Calendar date ) { } @ Override public void payForSomeone ( final List < Student > students , List < Lesson > lessons ) throws ParseException { LessonManagerDatabase db = new LessonManagerDatabase ( getApplicationContext ( ) ) ; this . studentsPayment = students ; this . lessonsPayment = lessons ; final Dialog dialogPayment = new Dialog ( this ) ; dialogPayment . setContentView ( custom_dialog_layout ) ; dialogPayment . setTitle ( "Payment" ) ; final Spinner spinnerStudents = ( ( Spinner ) ( dialogPayment . findViewById ( personlist ) ) ) ; final Spinner spinnerLessons = ( ( Spinner ) ( dialogPayment . findViewById ( numberLessons ) ) ) ; ButtonFlat pay = ( ( ButtonFlat ) ( dialogPayment . findViewById ( pay_button ) ) ) ; ButtonFlat back = ( ( ButtonFlat ) ( dialogPayment . findViewById ( back_button ) ) ) ; String [ ] studentArray = StringUtils . toStringArrayStudents ( students , false ) ; ArrayAdapter < String > adapterStudent = new ArrayAdapter ( this , layout . simple_spinner_item , studentArray ) ; adapterStudent . setDropDownViewResource ( simple_spinner_dropdown_item ) ; spinnerStudents . setAdapter ( adapterStudent ) ; spinnerStudents . setOnItemSelectedListener ( new AdapterView . OnItemSelectedListener ( ) { @ Override public void onItemSelected ( AdapterView < ? > parent , View view , int position , long id ) { LessonManagerDatabase db = new LessonManagerDatabase ( getApplicationContext ( ) ) ; try { lessonsPayment = db . getStudentLessonsPaid ( studentsPayment . get ( position ) . getId ( ) ) ; String [ ] lessonArray = StringUtils . generateLessonsArray ( lessonsPayment . size ( ) ) ; <START_BUG> ArrayAdapter < String > adapterLesson = new ArrayAdapter ( getApplicationContext ( ) , layout . simple_spinner_item , lessonArray ) ; <END_BUG> adapterLesson . setDropDownViewResource ( simple_spinner_dropdown_item ) ; spinnerLessons . setAdapter ( adapterLesson ) ; } catch ( ParseException e ) { e . printStackTrace ( ) ; } } @ Override public void onNothingSelected ( AdapterView < ? > parent ) { } } ) ; final String [ ] lessonArray = StringUtils . generateLessonsArray ( lessons . size ( ) ) ; ArrayAdapter < String > adapterLesson = new ArrayAdapter ( this , layout . simple_spinner_item , lessonArray ) ; adapterLesson . setDropDownViewResource ( simple_spinner_dropdown_item ) ; spinnerLessons . setAdapter ( adapterLesson ) ; dialogPayment . show ( ) ; pay . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { int moneyToPay = 0 ; final int lessonsToBePaid = ( spinnerLessons . getSelectedItemPosition ( ) ) + 1 ; for ( int i = 0 ; i < lessonsToBePaid ; i ++ ) { moneyToPay += lessonsPayment . get ( i ) . getFare ( ) ; } new AlertDialog . Builder ( MainActivity . this ) . setTitle ( "Pay<seq2seq4repair_space>Lessons" ) . setMessage ( ( ( "These<seq2seq4repair_space>lessons<seq2seq4repair_space>cost<seq2seq4repair_space>" + moneyToPay ) + "$,<seq2seq4repair_space>confirm?" ) ) . setPositiveButton ( yes , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int which ) { LessonManagerDatabase db = new LessonManagerDatabase ( getApplicationContext ( ) ) ; for ( int i = 0 ; i < lessonsToBePaid ; i ++ ) { Lesson l = lessonsPayment . get ( i ) ; l . setPaid ( true ) ; db . updateLesson ( l ) ; } Toast . makeText ( getApplicationContext ( ) , lessons_paid , LENGTH_LONG ) . show ( ) ; dialogPayment . cancel ( ) ; } } ) . setIcon ( ic_dialog_alert ) . create ( ) . show ( ) ; } } ) ; back . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { dialogPayment . cancel ( ) ; } } ) ; } }

Fix:
ArrayAdapter < String > adapterLesson = new ArrayAdapter ( getBaseContext ( ) , layout . simple_spinner_item , lessonArray ) ;