3

次のスニペットを使用して電話を特定のパターンで振動させていますが、ArrayIndexOutOfBoundsExceptionがスローされます。

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

しかし

vibrator.vibrate(VIBRATE_DURATION);

正常に動作します。ポインタはありますか?

4

1 に答える 1

11

ドキュメントは言う:

繰り返したい場合は、繰り返しを開始するパターンにインデックスを渡します。

あなたの場合、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();
    }
}
于 2011-02-06T19:05:38.757 に答える