• 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

Android, Java error "Syntax error on token "start", Identifier expected after this token"

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to android programming. I have this error "Syntax error on token "start", Identifier expected after this token". The code is shown below


Anyone, Please help .
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely the main.xml file is malformed.
 
Martin Thomas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Most likely the main.xml file is malformed.



Thanks for the reply, but i don't understand.
Here is my code





 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try adding an XML declaration.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is that you call timer.start() in the class' body, and not inside a method or other code block. You can't do that. You have to figure out where/when you want the timer thread to start. The least possible change would be:


Those brackets create an initializer block around the method call, so the call can be performed. This will cause the timer to be started when the class instance is created. You might consider moving that to one of the lifecycle methods (like onCreate()).

Your code also has a spurious semicolon after the end of the class-closing curly bracket.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D'oh! I was thinking this was a runtime problem.
 
Martin Thomas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:Your problem is that you call timer.start() in the class' body, and not inside a method or other code block. You can't do that. You have to figure out where/when you want the timer thread to start. The least possible change would be:


Those brackets create an initializer block around the method call, so the call can be performed. This will cause the timer to be started when the class instance is created. You might consider moving that to one of the lifecycle methods (like onCreate()).

Your code also has a spurious semicolon after the end of the class-closing curly bracket.






Thanks steve. I moved the timer to onCreate() method and it worked.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic