Vibrator.vibrate()抛出ArrayIndexOutOfBoundsException

时间:2011-02-06 18:56:26

标签: android exception vibrate

我使用以下代码段以特定模式振动手机,但它会抛出并且 ArrayIndexOutOfBoundsException

vibrator.vibrate(new long[] { selectedDuration, CONSTANT_DELAY }, REPEAT); 

但是

vibrator.vibrate(VIBRATE_DURATION);

工作正常。有什么指针吗?

1 个答案:

答案 0 :(得分:10)

文档说:

  

如果要重复,请将索引传递到开始重复的模式。

意味着REPEAT只允许为0或1。

这是实施:

public void vibrate(long[] pattern, int repeat)
{
    // catch this here because the server will do nothing.  pattern may
    // not be null, let that be checked, because the server will drop it
    // anyway
    if (repeat < pattern.length) {
        try {
            mService.vibratePattern(pattern, repeat, mToken);
        } catch (RemoteException e) {
        }
    } else {
        throw new ArrayIndexOutOfBoundsException();
    }
}
相关问题