【发布时间】:2017-07-08 21:01:03
【问题描述】:
这是我的代码片段:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.fragment_profile, container, false);
profile();
textView = (TextView) view.findViewById(R.id.textViewUsername);
listView = (ListView) view.findViewById(R.id.listView);
timer_start();
return view;
}
public void timer_start(){
final Runnable mTicker = new Runnable() {
@Override
public void run() {
sendRequest();
handler.postDelayed(mTicker, 5000); // error shows only for this line
}
};
handler.postDelayed(mTicker, 5000);
}
我想每 5 秒执行一次 sendRequest() 函数。但它显示错误:“变量 mTicker 可能尚未初始化”,而我正在调用 timer_start() 片段。
【问题讨论】:
-
对于纯粹的自我放纵,用自己提出和回答的问题来敲打这个问题,我们深表歉意。我只是认为它完全涵盖了您在这里提出的问题!