Buggy code:
; String [ ] projectionSubjects = new String [ ] { MyAverageDB . COLUMN_NAME_SUBJECT_ID , MyAverageDB . COLUMN_NAME_SUBJECT_NAME , MyAverageDB . COLUMN_NAME_SUBJECT_COEF } ; String sortOrderMarks = ( MyAverageDB . COLUMN_NAME_MARK_ID ) + "<seq2seq4repair_space>DESC" ; String sortOrderSubjects = ( MyAverageDB . COLUMN_NAME_SUBJECT_ID ) + "<seq2seq4repair_space>DESC" ; Cursor cursorSubjects = db . query ( TABLE_SUBJECTS , projectionSubjects , null , null , null , null , sortOrderSubjects ) ; nb_subjects = cursorSubjects . getCount ( ) ; cursorSubjects . moveToFirst ( ) ; while ( ! ( cursorSubjects . isAfterLast ( ) ) ) { int subjectId = cursorSubjects . getInt ( cursorSubjects . getColumnIndexOrThrow ( COLUMN_NAME_SUBJECT_ID ) ) ; String subjectTitle = cursorSubjects . getString ( cursorSubjects . getColumnIndexOrThrow ( COLUMN_NAME_SUBJECT_NAME ) ) ; String subjectCoef = cursorSubjects . getString ( cursorSubjects . getColumnIndexOrThrow ( COLUMN_NAME_SUBJECT_COEF ) ) ; if ( MainActivity . isNumeric ( subjectCoef ) ) myPromo . setSubject ( new Subject ( subjectId , subjectTitle , Double . parseDouble ( subjectCoef ) ) ) ; cursorSubjects . moveToNext ( ) ; } if ( ! ( myPromo . getListSubjects ( ) . isEmpty ( ) ) ) { Cursor cursorMarks = db . query ( TABLE_MARKS , projectionMarks , null , null , null , null , sortOrderMarks ) ; cursorMarks . moveToFirst ( ) ; while ( ! ( cursorMarks . isAfterLast ( ) ) ) { int markId = cursorMarks . getInt ( cursorMarks . getColumnIndexOrThrow ( COLUMN_NAME_MARK_ID ) ) ; String markValue = cursorMarks . getString ( cursorMarks . getColumnIndexOrThrow ( COLUMN_NAME_MARK_VALUE ) ) ; String markCoef = cursorMarks . getString ( cursorMarks . getColumnIndexOrThrow ( COLUMN_NAME_MARK_COEF ) ) ; String markSubjectID = cursorMarks . getString ( cursorMarks . getColumnIndexOrThrow ( COLUMN_NAME_SUBJECT_ID ) ) ; int markID = Integer . parseInt ( markSubjectID ) ; for ( int i = 0 ; i < ( myPromo . getListSubjects ( ) . size ( ) ) ; i ++ ) { if ( markID == ( myPromo . getListSubjects ( ) . get ( i ) . getId ( ) ) ) { myPromo . getListSubjects ( ) . get ( i ) . setTest ( markId , "" , "" , Double . parseDouble ( markValue ) , Double . parseDouble ( markCoef ) ) ; } } cursorMarks . moveToNext ( ) ; } } Double globalAverage = myPromo . getGlobalAverage ( ) ; if ( globalAverage > 1.0F ) { TextView globalMark = ( ( TextView ) ( findViewById ( textViewGlobalAverage ) ) ) ; globalMark . setText ( new String ( ( "" + globalAverage ) ) ) ; } ArrayList < String > listSubjects = new ArrayList < String > ( ) ; for ( int i = ( myPromo . getListSubjects ( ) . size ( ) ) - 1 ; i >= 0 ; i -- ) listSubjects . add ( myPromo . getListSubjects ( ) . get ( i ) . getName ( ) ) ; ListView lv = ( ( ListView ) ( findViewById ( listViewSubject ) ) ) ; ArrayAdapter adapter = new ArrayAdapter < String > ( this , layout . simple_list_item_1 , listSubjects ) ; lv . setAdapter ( adapter ) ; lv . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { public void onItemClick ( AdapterView < ? > av , View view , int i , long l ) { Intent in = new Intent ( MainActivity . this , SubjectActivity . class ) ; in . putExtra ( MainActivity . SUBJECT , "YES" ) ; in . putExtra ( MainActivity . ID_SUBJECT , new String ( ( "" + ( myPromo . getListSubjects ( ) . get ( ( ( ( nb_subjects ) - i ) - 1 ) ) . getId ( ) ) ) ) ) ; in . putExtra ( "TITLE_SUBJECT" , myPromo . getListSubjects ( ) . get ( ( ( ( nb_subjects ) - i ) - 1 ) ) . getName ( ) ) ; in . putExtra ( "COEF_SUBJECT" , new String ( ( "" + ( myPromo . getListSubjects ( ) . get ( ( ( ( nb_subjects ) - i ) - 1 ) ) . getCoefficient ( ) ) ) ) ) ; in . putExtra ( "AVERAGE_SUBJECT" , new String ( ( "" + ( myPromo . getListSubjects ( ) . get ( ( ( ( nb_subjects ) - i ) - 1 ) ) . getAverage ( ) ) ) ) ) ; startActivity ( in ) ; } } ) ; if ( ( nb_subjects ) < 2 ) { ImageView iv = ( ( ImageView ) ( findViewById ( superAndroid ) ) ) ; iv . setVisibility ( VISIBLE ) ; } Button addSubject = ( ( Button ) ( findViewById ( button_addSubject ) ) ) ; addSubject . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { Intent i = new Intent ( MainActivity . this , SubjectActivity . class ) ; i . putExtra ( MainActivity . SUBJECT , "NONE" ) ; if ( myPromo . getListSubjects ( ) . isEmpty ( ) ) <START_BUG> i . putExtra ( MainActivity . ID_SUBJECT , new String ( ( "" + 1 ) ) ) ; <END_BUG> else i . putExtra ( MainActivity . ID_SUBJECT , new String ( ( "" + ( ( getMaxId ( myPromo . getListSubjects ( ) ) ) + 1 ) ) ) ) ; startActivity ( i ) ; } } ) ; } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { } public static boolean isNumeric ( String str ) { } public int getMaxId ( ArrayList < Subject > array ) { } }

Fix:
i . putExtra ( MainActivity . ID_SUBJECT , new String ( "1" ) ) ;