eclipse 令牌“}”的语法错误,删除此令牌
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11570576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error on token "}", delete this token
提问by Eric
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
回答by cegfault
This is likely not an issue with your code, but Eclipse. Restart the computer, and then re-build the project.
这可能不是您的代码的问题,而是 Eclipse。重新启动计算机,然后重新生成项目。
If that does not work, try compiling with another program. If it works, then it's just Eclipse being weird.
如果这不起作用,请尝试使用另一个程序进行编译。如果它有效,那么它只是 Eclipse 很奇怪。
回答by Daniel DiPaolo
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.
粘贴时,错误消息不正确,并且您在正确的位置有正确数量的匹配大括号(尽管上面的缩进是无情的)。但是,除非出现无法正确匹配大括号的疯狂编译器极端情况,否则我猜您已经粘贴了除它抱怨的最后一个大括号之外的所有内容。按照错误消息的建议执行并删除它建议的行上的令牌。
回答by Bananeweizen
Upgrade your ADT plugin to version 20.0.1. This is a known bug in ADT 20.
将您的 ADT 插件升级到 20.0.1 版。这是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.
清理、重新创建项目等的所有其他技巧都不会永久解决问题,而只能解决一段时间,直到您碰巧再次触发错误。