This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Android and the fly likes Android, Java error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Android, Java error "Syntax error on token "start", Identifier expected after this token"" Watch "Android, Java error "Syntax error on token "start", Identifier expected after this token"" New topic
Author

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

Martin Thomas
Greenhorn

Joined: Feb 22, 2013
Posts: 3
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 .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
Most likely the main.xml file is malformed.


Ping & DNS - my free Android networking tools app
Martin Thomas
Greenhorn

Joined: Feb 22, 2013
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
Try adding an XML declaration.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4168
    
  21

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.


Steve
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
D'oh! I was thinking this was a runtime problem.
Martin Thomas
Greenhorn

Joined: Feb 22, 2013
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Android, Java error "Syntax error on token "start", Identifier expected after this token"
 
Similar Threads
Cannot Figure Out This Syntax Error
What is wrong with my code?
Message doesnt display continuously
Why error in this code
"identifier expected after this token"