Android : Android Java Application is freezing with No Error message being sent back

on Sunday, March 8, 2015


for some Reason my Android Java App is freezing when i press a certain button. However the app doesnt seem to be crashing since no error message is send back to Android Studio. It just freezes and after a while the app will restart.


Here is the Code that is executed on ButtonClick. I am aware that this is very confusing because i am using so many variables :/ i will try to put some declaration above the actualy Button Code.



ChronometerList = new Chronometer[]{Overtime1,Overtime2,Overtime3,Overtime4,Overtime5,Overtime6,Overtime7,Overtime8,Overtime9,Overtime10,Overtime11,Overtime12};
//is an Array of Chronometers

TimeList = new TextView[]{ TimeUntilTopic1Ends,TimeUntilTopic2Ends,TimeUntilTopic3Ends,TimeUntilTopic4Ends,TimeUntilTopic5Ends,TimeUntilTopic6Ends,TimeUntilTopic7Ends,TimeUntilTopic8Ends,TimeUntilTopic9Ends,TimeUntilTopic10Ends,TimeUntilTopic11Ends,TimeUntilTopic12Ends};
// Array of Textviews, that show us the Time Left, i need so many since i build a table out of lines and every line needs a timer

TopicTimer = new MyCounter[]{TopicTimer1,TopicTimer2,TopicTimer3,TopicTimer4,TopicTimer5,TopicTimer6,TopicTimer7,TopicTimer8,TopicTimer9,TopicTimer10,TopicTimer11,TopicTimer12};


// MyCounter is extended by Countdowntimer -> Simple Class //All the Timer are being build fine with no error


Here is the Code. Hella confusing but i hope you can help anyways :D



NextTopic.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO For some Reason this freezes the Whole Program
if(TimeList[row-1].getText().toString() == "Done")
{
ChronometerList[row-1].stop();
long ElapsedTimeInMillis = SystemClock.elapsedRealtime() - ChronometerList[row-1].getBase();
int RowUsed = 0;
int n = 0;
while(TimeList[row].getText()!= "null")
{
RowUsed++;
}

if(RowUsed != 0) {
int ElapsedTime = (int) (long) ElapsedTimeInMillis;
double SubtractionTime = ElapsedTime / RowUsed;

while (RowUsed >= n) {
TimeList[row + n].setText(String.valueOf(Double.parseDouble(TimeList[row + n].getText().toString()) - SubtractionTime));
n++;
}
row++;
TopicTimer[row-1].start();
}
else
{
//nothing yet

}


}
else
{


int RowsLeft = 0;
int n = 0;
while(TimeList[row].getText()!= null)
{
RowsLeft++;
}
// have to split up the text in there cause there are **m **s in it and not just the number
String TimeOutput = TimeList[row - 1].getText().toString();
String[] TimePartSeconds = TimeOutput.split("m ");
String Minutes = TimePartSeconds[0];
String SecondsLetters = TimePartSeconds[1];
String[] GetSeconds = SecondsLetters.split("s");
String seconds = GetSeconds[0];


int SecondsLeft = (Integer.valueOf(Minutes)*60) +(Integer.valueOf(seconds));
long AdditionTimeSeconds = SecondsLeft/RowsLeft;

TopicTimer[row-1].onFinish();


while (RowsLeft>= n) {
TimeList[row + n].setText(String.valueOf(Double.parseDouble(TimeList[row - 1 + n].getText().toString()) + (AdditionTimeSeconds/60)));
n++;
}
row++;
TopicTimer[row-1].start();
}
}
});

0 comments:

Post a Comment