令牌“,”,<上的语法错误预期&令牌上的语法错误,而是期望ConstructorHeaderName

时间:2013-07-03 19:29:02

标签: java syntax nested

我收到了错误:

Syntax error on token ",", < expected & Syntax error on tokens, ConstructorHeaderName expected instead

就行:

}, delay_interval, period);

我很确定某些内容被错误嵌套 - 但我不确定它到底是什么。

来源:

public class DataCountService extends Service {
    String text = "USR;1";
    String ERROR = Constants.PREFS_NAME;
    private Timer timer = new Timer();
    private long period;
    private long delay_interval;
    private long sms_timer;
    private long sms_period;
    private DeviceManagerUtilities dmUtilities = new DeviceManagerUtilities();
    private Context ctx;
    private Bundle extras;

    @SuppressWarnings("unused")
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(Constants.TAG, "Logging Service Started");

        extras = intent.getExtras();

        if (intent == null) {
            // Exit gracefully if service not started by intent
            Log.d(Constants.TAG, "Error: Null Intent");
        } else {

            if (extras != null) {

                if (extras.getString(Constants.DM_SMS_CONTENT).contains(
                        "//USR;1") 

                        && (extras.getString(Constants.PREFS_KEY_CALL_MADE)
                                .contains("TRUE"))) {

                    // set status to enabled
                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    Editor editor = settings.edit();
                    editor.putString("status", "1");
                    editor.commit();
                }  

                if (extras.getString(Constants.DM_SMS_CONTENT).contains( 
                        "//USR;0") 

                        || (extras.getString(Constants.PREFS_KEY_CALL_MADE)
                                .contains("FALSE"))) {

                    // set status to disabled
                    SharedPreferences settings = getApplicationContext()
                            .getSharedPreferences(Constants.PREFS_NAME, 0);
                    Editor editor = settings.edit();
                    editor.putString("status", "0");
                    editor.commit(); 
                } 

                sendSMS();

            }
        }
        return START_STICKY;
    }

    private void sendSMS() {

        // check enabled / disabled status 
        SharedPreferences settings = getApplicationContext()
                .getSharedPreferences(Constants.PREFS_NAME, 0);
        if (settings.getString("status", "0").equals(1)) {

            // check to ensure proper amount of time has lapsed

            // get current time
            long currentTimeMillis = System.currentTimeMillis() % 1000;

            // get the timestamp from the last time an SMS was sent
            long smsTimeStamp = settings.getLong("smstimestamp",
                    System.currentTimeMillis());

            // compare the two values to check to ensure proper amount of time has lapsed
            if (currentTimeMillis - smsTimeStamp > sms_timer) {



                final String newMdn = dmUtilities.swappedMdn(this);
                // get Wifi and Mobile traffic info
                double totalBytes = (double) TrafficStats.getTotalRxBytes()
                        + TrafficStats.getTotalTxBytes();
                double mobileBytes = TrafficStats.getMobileRxBytes()
                        + TrafficStats.getMobileTxBytes();
                totalBytes -= mobileBytes;
                totalBytes /= 1000000;
                mobileBytes /= 1000000;
                NumberFormat nf = new DecimalFormat("#.###");

                // get the date
                SimpleDateFormat s = new SimpleDateFormat("hh/mm/ss/MM/dd/yy");

                String tag = ";";

                // String mdn =
                // extras.getString(DataCountUtilities.swappedMdn(this));
                String mobileStr = nf.format(mobileBytes);
                String totalStr = nf.format(totalBytes);
                String DToDevice = s.format(new Date());
                String status = (settings.getString("status", "0"));

                String info = String.format("USI%sCN%s,WN%s", tag + status + tag
                        + settings.getString("0", newMdn) + tag + DToDevice + tag,
                        mobileStr, totalStr + settings.getString("last_month", ""));

                String lastMonth = String
                        .format("CO" + mobileStr + "WO" + totalStr);

                // save Network and Wifi data in sharedPreferences

                Editor editor = settings.edit();
                editor.putString("last_month", lastMonth);
                editor.commit();

                // set status to enabled
                editor.putString("status", "1");
                editor.commit();
                editor.putLong("smstimestamp", System.currentTimeMillis());
                editor.commit();

                // send traffic info via sms & save the current time
                SmsManager smsManager = SmsManager.getDefault();

                if (Config.DEVELOPMENT) {
                    String shortCode = settings.getString(
                            Constants.PREFS_KEY_SHORT_CODE,
                            Constants.DEFAULT_SHORT_CODE);
                    smsManager.sendTextMessage(shortCode, null, info, null, null);

                } else {
                    SmsManager ackSMS = SmsManager.getDefault();
                    smsManager.sendTextMessage(Constants.DEFAULT_SHORT_CODE, null,
                            info, null, null);

                }
            }
        }
    }
        @Override
        public void onCreate() {
            ctx = this;

            if (!Config.DEVELOPMENT) {

                period = Constants.PERIOD;
                delay_interval = Constants.DELAY_INTERVAL;
                sms_timer = Constants.SMS_TIMER;

            } else {

                period = Constants.DEBUG_PERIOD;
                delay_interval = Constants.DEBUG_DELAY_INTERVAL;
                sms_timer = Constants.DEBUG_SMS_TIMER;

            }
            startServiceTimer();

        }

        private void startServiceTimer() {
            timer.schedule(new TimerTask() {
                public void run() {

                    // send sms
                    sendSMS();
                }
            }

    }, delay_interval, period);


@Override
public IBinder onBind(Intent intent) {

    // TODO Auto-generated method stub

    return null;

}

@Override
public boolean onUnbind(Intent intent) {

    // TODO Auto-generated method stub

    return super.onUnbind(intent);

}

}

3 个答案:

答案 0 :(得分:1)

移动startServiceTimer的右括号以包含方法

private void startServiceTimer() {
    timer.schedule(new TimerTask() {
        public void run() {

            // send sms
            sendSMS();
        }

    // } from here
    }, delay_interval, period);
} <-- to here

答案 1 :(得分:0)

这是代码正确缩进的一部分。

private void startServiceTimer() {
    timer.schedule(new TimerTask() {
       public void run() {

          // send sms
          sendSMS();
       }
    }
}, delay_interval, period);

您没有完成new TimerTask()声明;声明的其余部分就在方法体结束之后。

这是您可能需要的:

private void startServiceTimer() {
    timer.schedule(new TimerTask() {
       public void run() {

          // send sms
          sendSMS();
       }
    }, delay_interval, period);  // , delay_interval, period); I moved it up a line
}

答案 2 :(得分:0)

您忘记关闭startServiceTimer方法。您应该添加以下行:

}
行后

}, delay_interval, period);