gpt4 book ai didi

java - mStartTime 无法解析为变量

转载 作者:行者123 更新时间:2023-11-29 21:09:42 25 4
gpt4 key购买 nike

我写了下面的代码:

package com.shadow.handler;

import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class ServiceClick extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
}
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = mStartTime;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;

if (seconds < 10) {
mTimeLabel.setText("" + minutes + ":0" + seconds);
} else {
mTimeLabel.setText("" + minutes + ":" + seconds);
}

mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
};

public void startClicked(View view) {
if (mStartTime == 0L) {
mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
}

public void stopClicked(View view) {
mHandler.removeCallbacks(mUpdateTimeTask);
}

}

我收到以下错误:

mStartTime cannot be resolved to a variable
mHandler cannot be resolved

但是我已经声明了mStartTime和mHandler。

最佳答案

您还没有声明这些变量。你需要声明它们

Handler mHandler;
long mStartTime;
@Override
public void onCreate(Bundle savedInstanceState) {

你还需要删除

import android.R;

应该是

import com.shadow.handler.R;

我也没有看到你在哪里初始化了mHandler

关于java - mStartTime 无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com