ERROR: "Syntax error on token"; "expected" Why?

Now I'm going crazy. Thought about it, thought about some kind of IDE error. Maybe I'm blind and can’t see anything ... but everything was fine just an hour ago. I commented on all the code and am not going to compile it.

public class CityExplorerPoi extends Activity { private POI displayedPOI = null; private MediaPlayer mPlayer; enum audioState { Idle, //Idle, not initialized Initialized, //Initialized, not prepared Prepared, //Prepared Started, //Playing Stopped, //needs preparing Paused, //can be Started or Stopped Preparing, //... End, //Released, useless Error, //... PlaybackCompleted //can be Started from beginning or Stopped }; audioState aState; <<<<<<<<<<ERROR mPlayer = new MediaPlayer(); } 

This code has a compiler error in the line marked ERROR, which indicates a syntax error on the token ";", expected

With the enum declaration, I tried to do without; after}. Tried to put; after the last record (PlaybackCompleted) and still nothing ???

Any ideas? What I miss: (

+6
source share
3 answers

This is an actual problem:

 mPlayer = new MediaPlayer(); 

This is just an instruction - but it is not in the constructor, method or other initializer. It is not clear why you are not just assigning a value at the declaration point:

 private MediaPlayer mPlayer = new MediaPlayer(); 

I would also recommend removing the redundant semicolon at the end of the listing declaration.

+16
source

This is not an IDE error.

You have a semicolon after closing} the listing. This is not required.

You also have mPlayer = new MediaPlayer(); floating in your code, outside the method.

I would suggest reading a good Java book, for example, this one: http://www.amazon.co.uk/Agile-Java-Crafting-Test-Driven-Development/dp/0131482394

And a good Android book: http://www.amazon.co.uk/Android-Application-Development-Dummies-Computers/dp/047077018X/ref=sr_1_1?s=books&ie=UTF8&qid=1333106527&sr=1-1

+4
source

The problem is here.

 mPlayer = new MediaPlayer(); 

You assign a value at the point of declaration. Similar.

 public class CityExplorerPoi extends Activity { private POI displayedPOI = null; enum audioState { Idle, //Idle, not initialized Initialized, //Initialized, not prepared Prepared, //Prepared Started, //Playing Stopped, //needs preparing Paused, //can be Started or Stopped Preparing, //... End, //Released, useless Error, //... PlaybackCompleted //can be Started from beginning or Stopped }; audioState aState; MediaPlayer mPlayer = new MediaPlayer(); } 
+1
source

Source: https://habr.com/ru/post/912042/


All Articles