• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

setText in for loop

Erather

Lurker
Hi!

I have just stated to look at Android app devoloping, and I try to learn eclipse and java programming. Mostly I have been watching tutorials and such and I haven't got that far, but i felt I wanted to try to make a small program.

I want the program to print one letter, after 0,5 s print another letter etc. I am using a TextView for this. The problem is that I get an error when I run the program in the emulator: "Unfortunately, 'name of app' has stopped".

Here is the code:

Code:
tLogo = (TextView) findViewById(R.id.tLogo);

Thread SplashTimer = new Thread(){ 
       public void run(){
        	try{
        		for (int Timer = 0; Timer < 10; Timer++){
        			sleep(500);
        			tLogo.setText(Letter[Timer]);
        		};
        	}
        	catch (InterruptedException e) {
			e.printStackTrace();
        	} 
   
        }
};

SplashTimer.start();

The name of the TextView is tLogo. The variable "Letter" is just a string array that I filled with the letters. The error does not appear directly but after like 0,5 s, so propably after the first loop. If i remove the line "tLogo.setText(Letter[Timer]);" I do not get the error, so even I figured out that the error is within this line.

Probably it is just a basic error, but I have tried for many hours to figure it out, but failed. It would be very nice if someone could help me with this. :) If you need more information feel free to ask!

Thanks in advance!
 
Back
Top Bottom