这有效:Thread.Sleep(1000)
这不起作用:Thread.Sleep(frequency)
frequency变量接受用户输入的edittext
并将其解析为整数,因此应该可以通过。我不知道我在做什么错。感谢帮助:)
private void FlashButtonClicked() {
startPattern = true;
try{
frequency = Long.parseLong(frequencyInput.getText().toString());
}catch(NumberFormatException e){
Toast.makeText(getBaseContext(), "value not acceptable", Toast.LENGTH_LONG).show();
}
frequency = (1 / frequency) * 1000;
while(startPattern){
enableTorch();
try{
// see if you can figure out why I can't pass the user input into the
//Thread.sleep() method without it fucking up. When you change it manually with
// a long input, it works just fine.
Thread.sleep(frequency);
}catch(Exception e){
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
如果频率属于long
类型并且大于1,则1/frequency
为零(因为/
表示整数除法)。替换为:frequency = 1000/frequency