Handler类发生了什么事。为什么它向我展示这种类型的错误?我可以通过调用Handler覆盖方法来解决它。但我不想要它们。我该怎么办。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
blink();
}
private void blink(){
final Handler handler = new Handler(); //showing error and need to call their override methods.
new Thread(new Runnable() {
@Override
public void run() {
int timeToBlink = 1000; //in milissegunds
try{Thread.sleep(timeToBlink);}catch (Exception e) {}
handler.post(new Runnable() {
@Override
public void run() {
TextView txt = (TextView) findViewById(R.id.blink);
if(txt.getVisibility() == View.VISIBLE){
txt.setVisibility(View.INVISIBLE);
}else{
txt.setVisibility(View.VISIBLE);
}
blink();
}
});
}
}).start();
}
}
即使我调用Handler方法,错误仍然存在。
@Override
public void close() {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
}
};
答案 0 :(得分:5)
您正在导入错误的Handler,您想使用android.os.Handler而不是java.util.logging.Handler。