• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse - setText in "for"-loop

 
Greenhorn
Posts: 2
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!




 
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Greenhorn
Posts: 9
Android
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
reply
    Bookmark Topic Watch Topic
  • New Topic