且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在令牌QUOT语法错误;}&QUOT ;,删除此令牌

更新时间:2022-10-19 11:32:33

这很可能不是一个问题,你的code,但是Eclipse。重新启动计算机,然后重新生成项目。

如果还是不行,请尝试使用其他程序编译。如果成功,那么它只是Eclipse的是奇怪的。

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

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.