java找不到禁止使用的符号方法
我想为选项卡式活动创建一个实时计时器
然而,这是我得到的错误:
Error:(29, 38) error: cannot find symbol method runOnUniThread()
这是我的代码:
package com.example.Sci.livetimeanddate;
import 安卓.icu.text.SimpleDateFormat;
import 安卓.os.Build;
import 安卓.support.annotation.Nullable;
import 安卓.support.annotation.RequiresApi;
import 安卓.support.v4.app.Fragment;
import 安卓.os.Bundle;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import 安卓.widget.Button;
import 安卓.widget.TextView;
import 安卓.widget.Toast;
public class sub_page01 extends Fragment {
private static final String TAG = "Sub_page01";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_sub_page01,container,false);
Thread t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
getActivity().runOnUniThread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.N)
public void run() {
TextView tdate = (TextView) view.findViewById(R.id.date);
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy\nhh-mm-ss a");
String dateString = sdf.format(date);
tdate.setText(dateString);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
return view;
}
}
我不确定是什么问题
# 1 楼答案
你在
runOnUniThread
中有一个输入错误。应该有runOnUiThread