Buggy code:
public class Phoenix extends ActionBarActivity implements View . OnClickListener { private static final String LOG_TAG = "Phoenix_Aktivity" ; private SharedPreferences mPrefs ; private TextView tv_currApp ; private TextView tv_currInterval ; private TextView tv_currTime ; private final ArrayList < String > installedAppNames = new ArrayList < > ( ) ; private final ArrayList < String > installedPackageNames = new ArrayList < > ( ) ; private final ArrayList < Drawable > installedAppIcons = new ArrayList < > ( ) ; private String [ ] installedAppsNamesArray ; private String [ ] installedPacksNamesArray ; private String packageToStart ; private String appToStart ; private int rebootInterval ; private int rebootTime ; @ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; if ( ( VERSION . SDK_INT ) >= 21 ) { getWindow ( ) . addFlags ( FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS ) ; getWindow ( ) . clearFlags ( FLAG_TRANSLUCENT_STATUS ) ; getWindow ( ) . setStatusBarColor ( getResources ( ) . getColor ( holo_orange_dark ) ) ; } setContentView ( phoenix ) ; mPrefs = getSharedPreferences ( "AutoReboot" , 0 ) ; getInstalledApps ( ) ; ImageButton b_cancel = ( ( ImageButton ) ( this . findViewById ( b_cancel ) ) ) ; b_cancel . setOnClickListener ( this ) ; ImageButton b_ok = ( ( ImageButton ) ( this . findViewById ( b_apply ) ) ) ; b_ok . setOnClickListener ( this ) ; ImageButton b_clear = ( ( ImageButton ) ( this . findViewById ( b_clear ) ) ) ; b_clear . setOnClickListener ( this ) ; tv_currApp = ( ( TextView ) ( this . findViewById ( R . id . tv_currApp ) ) ) ; tv_currInterval = ( ( TextView ) ( this . findViewById ( R . id . tv_currInterval ) ) ) ; tv_currTime = ( ( TextView ) ( this . findViewById ( R . id . tv_currTime ) ) ) ; packageToStart = mPrefs . getString ( "package" , "" ) ; appToStart = mPrefs . getString ( "app" , getResources ( ) . getString ( app_name ) ) ; rebootInterval = mPrefs . getInt ( "interval" , 99 ) ; rebootTime = mPrefs . getInt ( "time" , 99 ) ; tv_currApp . setText ( appToStart ) ; tv_currInterval . setText ( ( ( String . valueOf ( rebootInterval ) ) + "<seq2seq4repair_space>day" ) ) ; tv_currTime . setText ( ( ( String . valueOf ( rebootTime ) ) + "<seq2seq4repair_space>o'clock" ) ) ; Phoenix . concurrentSort ( installedAppNames , installedAppNames , installedAppIcons , installedPackageNames ) ; installedAppsNamesArray = new String [ installedAppNames . size ( ) ] ; installedAppsNamesArray = installedAppNames . toArray ( installedAppsNamesArray ) ; installedPacksNamesArray = new String [ installedAppNames . size ( ) ] ; installedPacksNamesArray = installedPackageNames . toArray ( installedPacksNamesArray ) ; Drawable [ ] installedAppsIconArray = new Drawable [ installedAppIcons . size ( ) ] ; installedAppsIconArray = installedAppIcons . toArray ( installedAppsIconArray ) ; boolean hasHistory = false ; int nameIndex = 0 ; int intervalIndex = 0 ; int timeIndex = 0 ; if ( ! ( packageToStart . equalsIgnoreCase ( "" ) ) ) { if ( installedAppNames . contains ( appToStart ) ) { nameIndex = installedAppNames . indexOf ( appToStart ) ; intervalIndex = ( rebootInterval ) - 1 ; if ( ( rebootTime ) == 0 ) { <START_BUG> timeIndex = 24 ; <END_BUG> } else { timeIndex = ( rebootTime ) - 1 ; } hasHistory = true ; } } InstalledAppsList appsListAdapter = new InstalledAppsList ( this , installedAppsNamesArray , installedAppsIconArray ) ; ListView lv_installedApps = ( ( ListView ) ( findViewById ( lv_installedApps ) ) ) ; lv_installedApps . setAdapter ( appsListAdapter ) ; if ( hasHistory ) { lv_installedApps . setItemChecked ( nameIndex , true ) ; lv_installedApps . smoothScrollToPosition ( nameIndex ) ; } lv_installedApps . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { @ Override public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) { packageToStart = installedPacksNamesArray [ position ] ; appToStart = installedAppsNamesArray [ position ] ; tv_currApp . setText ( appToStart ) ; } } ) ; String [ ] intervalDays = getResources ( ) . getStringArray ( intervals ) ; ListView lv_rebootDay = ( ( ListView ) ( findViewById ( lv_rebootDay ) ) ) ; IntervalList intervalArrayAdapter = new IntervalList ( this , intervalDays ) ; lv_rebootDay . setAdapter ( intervalArrayAdapter ) ; if ( hasHistory ) { lv_rebootDay . setItemChecked ( intervalIndex , true ) ; lv_rebootDay . smoothScrollToPosition ( intervalIndex ) ; } lv_rebootDay . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { @ Override public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) { rebootInterval = ( ( int ) ( id ) ) + 1 ; tv_currInterval . setText ( ( ( String . valueOf ( rebootInterval ) ) + "<seq2seq4repair_space>day" ) ) ; } } ) ; String [ ] resetTime = getResources ( ) . getStringArray ( times ) ; ListView lv_rebootTimer = ( ( ListView ) ( findViewById ( lv_rebootTimer ) ) ) ; TimeList resetTimeArrayAdapter = new TimeList ( this , resetTime ) ; lv_rebootTimer . setAdapter ( resetTimeArrayAdapter ) ; if ( hasHistory ) { lv_rebootTimer . setItemChecked ( timeIndex , true ) ; lv_rebootTimer . smoothScrollToPosition ( timeIndex ) ; } lv_rebootTimer . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { @ Override public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) { rebootTime = ( ( int ) ( id ) ) + 1 ; tv_currTime . setText ( ( ( String . valueOf ( rebootTime ) ) + "<seq2seq4repair_space>o'clock" ) ) ; } } ) ; } @ Override public void onClick ( View v ) { } private void getInstalledApps ( ) { }

Fix:
timeIndex = 23 ;