Buggy code:
TableRow buttonRow = ( ( TableRow ) ( findViewById ( buttonRow ) ) ) ; buttonRow . setGravity ( CENTER ) ; buttonRow . setLayoutParams ( new LayoutParams ( LayoutParams . WRAP_CONTENT , LayoutParams . WRAP_CONTENT ) ) ; if ( TablePainterActivity . imageMap . containsKey ( "concordia" ) ) { Button viewConcordiaButton = new Button ( this ) ; viewConcordiaButton . setTextColor ( BLACK ) ; viewConcordiaButton . setTextSize ( ( ( float ) ( 13 ) ) ) ; viewConcordiaButton . setText ( "Concordia" ) ; viewConcordiaButton . setTypeface ( DEFAULT_BOLD ) ; viewConcordiaButton . setPadding ( 15 , 15 , 15 , 15 ) ; viewConcordiaButton . setGravity ( CENTER ) ; viewConcordiaButton . setBackgroundColor ( getResources ( ) . getColor ( light_grey ) ) ; viewConcordiaButton . setLayoutParams ( new LayoutParams ( LayoutParams . WRAP_CONTENT , LayoutParams . WRAP_CONTENT ) ) ; buttonRow . addView ( viewConcordiaButton ) ; viewConcordiaButton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { ConnectivityManager connectivityManager = ( ( ConnectivityManager ) ( getSystemService ( CONNECTIVITY_SERVICE ) ) ) ; NetworkInfo mobileWifi = connectivityManager . getNetworkInfo ( TYPE_WIFI ) ; if ( mobileWifi . isConnected ( ) ) { Toast . makeText ( TablePainterActivity . this , "Opening<seq2seq4repair_space>Concordia<seq2seq4repair_space>Image..." , LENGTH_LONG ) . show ( ) ; Intent viewConcordiaIntent = new Intent ( Intent . ACTION_VIEW , Uri . parse ( TablePainterActivity . imageMap . get ( "concordia" ) . getImageURL ( ) ) ) ; startActivity ( viewConcordiaIntent ) ; } else { Toast . makeText ( TablePainterActivity . this , "Please<seq2seq4repair_space>check<seq2seq4repair_space>your<seq2seq4repair_space>internet<seq2seq4repair_space>connection<seq2seq4repair_space>to<seq2seq4repair_space>view<seq2seq4repair_space>this<seq2seq4repair_space>image." , LENGTH_LONG ) . show ( ) ; } } } ) ; } if ( TablePainterActivity . imageMap . containsKey ( "probability_density" ) ) { Button viewProbabilityDensityButton = new Button ( this ) ; viewProbabilityDensityButton . setTextSize ( ( ( float ) ( 13 ) ) ) ; viewProbabilityDensityButton . setText ( "Probability<seq2seq4repair_space>Density" ) ; viewProbabilityDensityButton . setTypeface ( DEFAULT_BOLD ) ; viewProbabilityDensityButton . setPadding ( 15 , 15 , 15 , 15 ) ; viewProbabilityDensityButton . setGravity ( CENTER ) ; if ( TablePainterActivity . imageMap . containsKey ( "concordia" ) ) { viewProbabilityDensityButton . setBackgroundColor ( getResources ( ) . getColor ( button_blue ) ) ; viewProbabilityDensityButton . setTextColor ( WHITE ) ; } else { viewProbabilityDensityButton . setBackgroundColor ( getResources ( ) . getColor ( light_grey ) ) ; viewProbabilityDensityButton . setTextColor ( BLACK ) ; } viewProbabilityDensityButton . setLayoutParams ( new LayoutParams ( LayoutParams . WRAP_CONTENT , LayoutParams . WRAP_CONTENT ) ) ; buttonRow . addView ( viewProbabilityDensityButton ) ; viewProbabilityDensityButton . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { ConnectivityManager connectivityManager = ( ( ConnectivityManager ) ( getSystemService ( CONNECTIVITY_SERVICE ) ) ) ; NetworkInfo mobileWifi = connectivityManager . getNetworkInfo ( TYPE_WIFI ) ; if ( mobileWifi . isConnected ( ) ) { Toast . makeText ( TablePainterActivity . this , "Opening<seq2seq4repair_space>Probability<seq2seq4repair_space>Density<seq2seq4repair_space>Image..." , LENGTH_LONG ) . show ( ) ; Intent viewProbabilityDensityIntent = new Intent ( Intent . ACTION_VIEW , Uri . parse ( TablePainterActivity . imageMap . get ( "probability_density" ) . getImageURL ( ) ) ) ; startActivity ( viewProbabilityDensityIntent ) ; } else { Toast . makeText ( TablePainterActivity . this , "Please<seq2seq4repair_space>check<seq2seq4repair_space>your<seq2seq4repair_space>internet<seq2seq4repair_space>connection<seq2seq4repair_space>to<seq2seq4repair_space>view<seq2seq4repair_space>this<seq2seq4repair_space>image." , LENGTH_LONG ) . show ( ) ; } } } ) ; } HorizontalScrollView screenScroll = ( ( HorizontalScrollView ) ( findViewById ( horizontalScrollView ) ) ) ; LinearLayout tableLayout = ( ( LinearLayout ) ( findViewById ( displayTableLayout ) ) ) ; TableLayout categoryNameTable = ( ( TableLayout ) ( findViewById ( categoryNameTable ) ) ) ; TableLayout headerInformationTable = ( ( TableLayout ) ( findViewById ( tableForHeader ) ) ) ; ScrollView scrollPane = ( ( ScrollView ) ( findViewById ( scrollPane ) ) ) ; TableLayout aliquotDataTable = ( ( TableLayout ) ( findViewById ( finalTable ) ) ) ; <START_BUG> final int ROWS = 4 + ( TablePainterActivity . fractionMap . size ( ) ) ; <END_BUG> final int COLS = outputVariableNames . size ( ) ; int [ ] columnSizes = distributeTableColumns ( finalArray , ROWS , COLS ) ; int [ ] headerCellSizes = distributeHeaderCells ( columnSizes ) ; TableRow categoryRow = new TableRow ( this ) ; categoryNameTable . addView ( categoryRow ) ; int categoryCount = 0 ; Iterator < Map . Entry < Integer , Category > > iterator = TablePainterActivity . categoryMap . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Map . Entry < Integer , Category > category = iterator . next ( ) ; if ( ( category . getValue ( ) . getColumnCount ( ) ) != 0 ) { TextView categoryCell = new TextView ( this ) ; categoryCell . setText ( category . getValue ( ) . getDisplayName ( ) ) ; categoryCell . setTypeface ( MONOSPACE ) ; if ( ( category . getValue ( ) . getDisplayName ( ) . contentEquals ( "Fraction" ) ) && ( categoryCount != 0 ) ) { categoryCell . setMinEms ( ( ( columnSizes [ ( ( columnSizes . length ) - 1 ) ] ) + 2 ) ) ; } else { categoryCell . setMinEms ( ( ( headerCellSizes [ categoryCount ] ) + ( 2 * ( category . getValue ( ) . getColumnCount ( ) ) ) ) ) ; } categoryCell . setPadding ( 3 , 4 , 3 , 4 ) ; categoryCell . setTextSize ( ( ( float ) ( 14.5 ) ) ) ; categoryCell . setTextColor ( BLACK ) ; categoryCell . setBackgroundResource ( background_blue_background ) ; categoryCell . setGravity ( LEFT ) ; categoryRow . addView ( categoryCell ) ; categoryCount ++ ; } } int rowCount = 1 ; for ( int currentRow = 1 ; currentRow < ROWS ; currentRow ++ ) { TableRow row = new TableRow ( this ) ;

Fix:
final int ROWS = 5 + ( TablePainterActivity . fractionMap . size ( ) ) ;