Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tyasia Sweets
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a android root app and I am using an open source code provided by the person that is teaching people how to make the root app my only issue is after making all the needed corrections to the code and then getting to the end i have this one error saying syntax error "start", Identifier expected after this token what is the fix for this can anyone help please and also this is my first time making an app on my own using java i have provided my screen shot below and my second issue which i am also going to provide a screen shot for is on my main activity i receive this error Syntax error on token "}", delete this token but if i delete the token then my line that says final Button button1 = Button findViewById(R.id.button1); will give me and error with a little light bulb that says unreachable code and if i click on the little light bulb it has a big x and remove next to it in one box and then in the other box next to that one it has this
...
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
...
but as long as i keep that token on the bottom of the screen it will not give me the little light bulb which you will see in my screen shots i am going to provide two one with and one without the token I would like to know the fix for this as well
shell.png
[Thumbnail for shell.png]
"start', identifier erroe
main activity with the token as the error.png
[Thumbnail for main activity with the token as the error.png]
token as the error
after token deleted.png
[Thumbnail for after token deleted.png]
after the token is deleted error
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Rather than posting screenshots, it is much better to copy and paste the error messages you get into the forum. Also, we probably need to see the code (when you do post your code, please read this first: UseCodeTags <= link).

The problem comes from the fact that you have either a missing or extra curly braces ('}') someplace. You should check your code line by line and make sure that your brackets line up. This is usually made easier if you use consistent spacing and line up the open and close brackets so that they are in the same column. For example:
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it looks like the problems are this:

1) The error on the button comes because you are missing a } at the end of the onCreateOptions() method. So that method has a line that returns true, then the line with the Button on it is considered to be part of the method, since you do not have the } bracket. Since the previous line was a return statement, there would be no way to get to the next line in the same method, and you get that error. But the problem is that you did not close the method.

2) The error for the extra token is because it is an extra token. The previous two lines are both }, one is closes the method setNewTextInTextView(), and the other one closes the class. So the one on the last line is one too many. Remove it, or remove the one above it (to keep bracket alignment).

3) The error on the t.start() line is probably because you are not putting that code in a method or initialization block. You can not execute arbitrary code the class body proper, you can only declare variables, constructors, methods, initialization blocks, and inner classes. To execute code you need a code block. Find a good method (such as the constructor or some other method that makes sense) in which the Thread should be started. Note that the thread can only be started once. So make sure you are declaring it and using it appropriately.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic