无法解析符号" postDelayed"

时间:2016-07-14 13:59:35

标签: java android

我有错误:无法解析符号" postDelayed"。在:

package com.example.hubert.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

public class ClickActivity extends AppCompatActivity {
    Handler handler = new Handler();

    Runnable updateCurrentTime = new Runnable() {
        @Override
        public void run() {
            money = money + 100;
            handler.postDelayed(this, 1000);
        }
    };
    handler.postDelayed(updateCurrentTime, 500);
(...)
}

这是我的一些代码:

{{1}}

我读了其他类似的问题,所有答案都很糟糕。

1 个答案:

答案 0 :(得分:2)

您必须将语句放在方法中。

与此类似:

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_main);

    handler.postDelayed(updateCurrentTime, 500);

}