Syntax error on token “}”, delete this token

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I keep getting this error saying "Syntax error on token "}", delete this token." on the last line, why? I have searching for the error but I can't seem to find it. As you can see it's a service, calling on another service every once in a while.

package com.iggeman.updater;  import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log;  public class UpdaterService extends Service {  private static final String TAG = UpdaterService.class         .getSimpleName(); private Updater updater; public boolean isRunning = false;  @Override public IBinder onBind(Intent intent) {     // TODO Auto-generated method stub     return null; }  @Override public void onCreate() {     // TODO Auto-generated method stub     super.onCreate();      updater = new Updater();      Log.d(TAG, "onCreate"); }  @Override public void onStart(Intent intent, int startId) {     // TODO Auto-generated method stub     super.onStart(intent, startId);      if (this.isRunning == false) {         updater.start();         this.isRunning = true;     }      Log.d(TAG, "onStart"); }  @Override public synchronized void onDestroy() {     // TODO Auto-generated method stub     super.onDestroy();      if (this.isRunning) {         updater.interrupt();     }      updater = null;      Log.d(TAG, "onDestroy"); }  class Updater extends Thread {     static final long DELAY = 10000;     private boolean isRunning = false;      public Updater() {         super("Updater");     }      @Override     public void run() {         // TODO Auto-generated method stub         super.run();         isRunning = true;         while (isRunning) {             try {                 // Do something                  startService(new Intent(getBaseContext(), StartServiceTwo.class));                  Log.d(TAG, "Updater running");                  Thread.sleep(DELAY);             } catch (InterruptedException e) {                 // interrupted                 isRunning = false;             }         } // while     }      public boolean isRunning() {         return this.isRunning();     } } } 

I have gone through all the brackets and I can't find anyone that isn't where it's supposed to be.

Edit:

Still the error:

package com.iggeman.updater;  import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log;  public class UpdaterService extends Service {  private static final String TAG = UpdaterService.class         .getSimpleName(); private Updater updater; public boolean isRunning = false;  @Override public IBinder onBind(Intent intent) {     // TODO Auto-generated method stub     return null; }  @Override public void onCreate() {     // TODO Auto-generated method stub     super.onCreate();      updater = new Updater();      Log.d(TAG, "onCreate"); }  @Override public void onStart(Intent intent, int startId) {     // TODO Auto-generated method stub     super.onStart(intent, startId);      if (this.isRunning == false) {         updater.start();         this.isRunning = true;     }      Log.d(TAG, "onStart"); }  @Override public synchronized void onDestroy() {     // TODO Auto-generated method stub     super.onDestroy();      if (this.isRunning) {         updater.interrupt();     }      updater = null;      Log.d(TAG, "onDestroy"); }  class Updater extends Thread {     static final long DELAY = 10000;     private boolean isRunning = false;      public Updater() {         super("Updater");     }      @Override     public void run() {         // TODO Auto-generated method stub         super.run();         isRunning = true;         while (isRunning) {             try {                 // Do something                  startService(new Intent(getBaseContext(), StartServiceTwo.class));                  Log.d(TAG, "Updater running");                  Thread.sleep(DELAY);             } catch (InterruptedException e) {                 // interrupted                 isRunning = false;             }         } // while     } //Run      } //Class updater  public boolean isRunning() {         return this.isRunning();    } }  //Main body 

回答1:

This is likely not an issue with your code, but Eclipse. Restart the computer, and then re-build the project.

If that does not work, try compiling with another program. If it works, then it's just Eclipse being weird.



回答2:

As-pasted, the error message is incorrect and you have the proper number of matching braces in the right places (though the indentation above is unforgiving). However, barring a crazy compiler corner-case that can't match braces correctly, I'm guessing you've pasted all but that last brace that it's complaining about. Do as the error message suggests and delete the token on the line it suggests.



回答3:

Upgrade your ADT plugin to version 20.0.1. This is a known bug in ADT 20.

All the other tips for cleaning, re-creating the project and so on will not solve the issue permanently, but only for a while, until you happen to trigger the bug again.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!