Java 无法使用振动器

Java 无法使用振动器,java,android,vibration,pulse,Java,Android,Vibration,Pulse,我正在尝试在我的应用程序中实现一个功能,它可以给振动器脉冲。 用户可以使用滑块更改3项内容:振动强度、脉冲长度和脉冲间隔时间 我在想一些代码,比如: for(i=0; i<(pulse length * whatever)+(pulse gap * whatever); i+=1){ pattern[i]=pulse length*i; patern[i+1]=pulse gap; for(i=0;i我唯一的猜测是您收到了一个ArrayIndexOutOfBounds错误 如果是这样,在

我正在尝试在我的应用程序中实现一个功能,它可以给振动器脉冲。 用户可以使用滑块更改3项内容:振动强度、脉冲长度和脉冲间隔时间

我在想一些代码,比如:

for(i=0; i<(pulse length * whatever)+(pulse gap * whatever); i+=1){
pattern[i]=pulse length*i;
patern[i+1]=pulse gap;

for(i=0;i我唯一的猜测是您收到了一个ArrayIndexOutOfBounds错误

如果是这样,在尝试填充数组之前,需要定义
long
数组的长度

long[] OutOfBounds = new long[];
OutOfBounds[0] = 100;
// this is an error, it's trying to access something that does not exist.

long[] legit = new long[3];
legit[0] = 0;
legit[1] = 500;
legit[2] = 1000;
// legit[3] = 0; Again, this will give you an error. 
vibrate()
是一个智能函数。这两个示例都不会引发错误:

v.vibrate(legit, 0);
// vibrate() combines both legit[0] + legit[2] for the 'off' time

long tooLegit = new long[100];
tooLegit[0] = 1000;
tooLegit[1] = 500;
tooLegit[10] = 100;
tooLegit[11] = 2000;
v.vibrate(tooLegit, 0);
// vibrate() skips over the values you didn't define, ie long[2] = 0, long[3] = 0, etc

希望这能有所帮助。

我唯一的猜测是您收到了一个ArrayIndexOutOfBounds错误

如果是这样,在尝试填充数组之前,需要定义
long
数组的长度

long[] OutOfBounds = new long[];
OutOfBounds[0] = 100;
// this is an error, it's trying to access something that does not exist.

long[] legit = new long[3];
legit[0] = 0;
legit[1] = 500;
legit[2] = 1000;
// legit[3] = 0; Again, this will give you an error. 
vibrate()
是一个智能函数。这两个示例都不会引发错误:

v.vibrate(legit, 0);
// vibrate() combines both legit[0] + legit[2] for the 'off' time

long tooLegit = new long[100];
tooLegit[0] = 1000;
tooLegit[1] = 500;
tooLegit[10] = 100;
tooLegit[11] = 2000;
v.vibrate(tooLegit, 0);
// vibrate() skips over the values you didn't define, ie long[2] = 0, long[3] = 0, etc

希望这有帮助。

请发布您的错误跟踪。请发布您的错误跟踪。