GeeCON Prague 2014*
The moose likes Android and the fly likes Eclipse - setText in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Eclipse - setText in "for"-loop" Watch "Eclipse - setText in "for"-loop" New topic
Author

Eclipse - setText in "for"-loop

J Sundin
Greenhorn

Joined: Mar 05, 2012
Posts: 2

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:



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. If I move this line outside the "for"-loop it also works, but then it's pointless ;).

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!




Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

Hi !

Try this code:



and do not start name you variables with capital letter, int timer not Timer, firstly try with this : http://java.about.com/od/javasyntax/a/nameconventions.htm or http://docs.oracle.com/javase/tutorial/index.html



Don Ho
Greenhorn

Joined: Mar 07, 2012
Posts: 9

You cannot modify the UI from a thread other than the main thread. Since your SplashTimer thread sets the text for the Textview, it violates this rule. Replace that line with the following:

For more information read this.
J Sundin
Greenhorn

Joined: Mar 05, 2012
Posts: 2

Worked! Thanks again, both of you, totaly made my day! Thanks for the links as well. I am not so experienced in programming, so I need all the help I can get!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse - setText in "for"-loop