Buggy code:
public class ContactEncodeActivity extends AppCompatActivity { private static final boolean DEBUG = false ; public static final String FILE_NAME_KEY = "soft.swenggroup5.EncodeActivity.FILENAMEKEY" ; public static final String FILE_PATH_KEY = "soft.swenggroup5.EncodeActivity.FILEPATHKEY" ; public ImageView contactQRCode ; public List < String > qrCodes ; public int index ; public int maxQrCodes ; public TextView currentCode ; protected void onCreate ( final Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; setContentView ( sending_codes ) ; Log . d ( "onCreate_CEA" , "On<seq2seq4repair_space>create" ) ; Button newContact = ( ( Button ) ( findViewById ( selectNewContact ) ) ) ; Button mainMenu = ( ( Button ) ( findViewById ( mainMenu ) ) ) ; contactQRCode = ( ( ImageView ) ( findViewById ( imageView2 ) ) ) ; newContact . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View w ) { finish ( ) ; } } ) ; mainMenu . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View w ) { startActivity ( new Intent ( ContactEncodeActivity . this , MainActivity . class ) ) ; } } ) ; Button nextCode = ( ( Button ) ( findViewById ( nextCode ) ) ) ; Button previousCode = ( ( Button ) ( findViewById ( previousCode ) ) ) ; nextCode . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View w ) { try { Log . d ( "TAG" , ( "Encoded<seq2seq4repair_space>into<seq2seq4repair_space>a<seq2seq4repair_space>qr<seq2seq4repair_space>code:<seq2seq4repair_space>" + ( qrCodes . get ( index ) ) ) ) ; if ( ( index ) < ( maxQrCodes ) ) { contactQRCode . setImageBitmap ( EncoderUtils . generateQRCodeBitmap ( qrCodes . get ( ( ( index ) ++ ) ) ) ) ; currentCode . setText ( ( ( ( index ) + "//" ) + ( maxQrCodes ) ) ) ; } } catch ( Exception e ) { } } } ) ; previousCode . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View w ) { try { Log . d ( "TAG" , ( "Encoded<seq2seq4repair_space>into<seq2seq4repair_space>a<seq2seq4repair_space>qr<seq2seq4repair_space>code:<seq2seq4repair_space>" + ( qrCodes . get ( index ) ) ) ) ; if ( ( ( index ) - 1 ) > 0 ) { contactQRCode . setImageBitmap ( EncoderUtils . generateQRCodeBitmap ( qrCodes . get ( ( ( -- ( index ) ) - 1 ) ) ) ) ; currentCode . setText ( ( ( ( index ) + "//" ) + ( maxQrCodes ) ) ) ; } } catch ( Exception e ) { } } } ) ; Intent receivedIntent = getIntent ( ) ; String filePath = receivedIntent . getStringExtra ( ContactEncodeActivity . FILE_PATH_KEY ) ; File contactFile = new File ( filePath ) ; try { qrCodes = EncoderUtils . encodeFileToQRStrings ( contactFile ) ; index = 0 ; Log . d ( "TAG" , ( "Encoded<seq2seq4repair_space>into<seq2seq4repair_space>a<seq2seq4repair_space>qr<seq2seq4repair_space>code:<seq2seq4repair_space>" + ( qrCodes . get ( index ) ) ) ) ; contactQRCode . setImageBitmap ( EncoderUtils . generateQRCodeBitmap ( qrCodes . get ( ( ( index ) ++ ) ) ) ) ; contactQRCode . setAdjustViewBounds ( true ) ; contactQRCode . setScaleType ( FIT_CENTER ) ; TextView contactName = ( ( TextView ) ( findViewById ( contactName ) ) ) ; contactName . setText ( ( "Contact:<seq2seq4repair_space>" + ( receivedIntent . getStringExtra ( ContactEncodeActivity . FILE_NAME_KEY ) ) ) ) ; currentCode = ( ( TextView ) ( findViewById ( R . id . currentCode ) ) ) ; <START_BUG> maxQrCodes = ( qrCodes . size ( ) ) - 1 ; <END_BUG> currentCode . setText ( ( "1//" + ( maxQrCodes ) ) ) ; } catch ( WriterException e ) { if ( ContactEncodeActivity . DEBUG ) Log . e ( "onActivityResult" , e . toString ( ) ) ; } } }

Fix:
maxQrCodes = qrCodes . size ( ) ;