2011-02-06 18 views
2

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

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

しかし

vibrator.vibrate(VIBRATE_DURATION); 

が正常に動作します。すべてのポインタ?

答えて

9

ドキュメントは言う:

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

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(); 
    } 
} 
+0

REPEATはもちろんの0または1のいずれか – Thomas

+0

おかげであってもよい...修正します。 – sstn

+0

ありがとうございました。 –

関連する問題