我遇到错误:无法解析符号“postDelayed”。在:
handler.postDelayed(updateCurrentTime, 500);
这是我的一些代码:
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);
(...)
}
我读过其他类似的问题,但没有一个答案对我有用。
最佳答案
您必须将语句放入方法中。
与此类似:
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
handler.postDelayed(updateCurrentTime, 500);
}
关于java - 无法解析符号 "postDelayed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38376261/