Forums Register Login

Eclipse - setText in "for"-loop

+Pie Number of slices to send: Send
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!




+Pie Number of slices to send: Send
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



1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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!
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5792 times.
Similar Threads
Help needed with java.util.Timer
Android: Add custom widget or view (ex. vertical bar) which changes height programmatically
android uncaught handler: thread main exiting due to uncaught exception
Thread synchronization
Android: Cannot show more than one image
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:49:27.