我不断收到此错误消息,提示“令牌“}”上的语法错误,请删除此令牌。” 在最后一行,为什么?我一直在寻找错误,但似乎找不到。如您所见,它是一项服务,每隔一段时间就会调用另一项服务。
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();
}
}
}
我已经翻遍了所有的括号,但我找不到任何不在它应该在的地方的人。
编辑:
仍然是错误:
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