ayuda con una excpetion

jhosua
22 de Junio del 2004
hola amigos tengo un problema y no se como resolverlo es una excepcion q esta marcada en las siguientes lineas, si alguno puede ayudarme a resolver este problema se los voy a agradecer toda la vida, o pueden decirme +/- como resolverlo gracias

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
at FastrakInputDevice.getSensor(FastrakInputDevice.java:96)
at DigiLoop.<init>(DigiLoop.java:327)
at DigiLoop.main(DigiLoop.java:370)

Jorge
22 de Junio del 2004
La respuesta esta en la exception java.lang.ArrayIndexOutOfBoundsException.

Esto pasa cuando estas tratando de acedir un index mayor que el de tu array. Por ejemplo:

// tu array index es 4 elementos [0],[1],[2],[3]
int myArray = new int[4];
// no exception
for(int i=0; i < myArray.length; ++i) {
myArray[i] = i;
}

// cuando llege al i=4, Exception is thrown
for(int i=0; i < 5; ++i) {
myArray[i] = i;
}


jhosua
22 de Junio del 2004
gracias Jorge, sabes ya cheq todo y no veo el error espero y puedas ayudarme un poco mas, te lo agradesco mucho gracias.

este es el modulo del codigo donde tengo el error

import javax.media.j3d.*;
import javax.vecmath.*;

public class FastrakInputDevice implements InputDevice {

private FastrakDriver polhemus;
private Sensor [] polhemusSensor;
private SensorRead [] polhemusSensorRead;

private Transform3D [] initPosTransform;
private Transform3D [] initOriTransform;

private int polhemusActiveReceivers;

private Transform3D polhemusTransform = new Transform3D();
private float [] polhemusPos = new float[3];
private float [] polhemusOri = new float[3];

private Transform3D posTransform = new Transform3D();
private Transform3D oriTransform = new Transform3D();
private Vector3f posVector = new Vector3f();
private Transform3D trans = new Transform3D();

private float sensitivity = 1.0f;
private float angularRate = 1.0f;
private float x, y, z;

public FastrakInputDevice(FastrakDriver polhemus)
{
this.polhemus = polhemus;
polhemusActiveReceivers = polhemus.getActiveReceivers();

polhemusSensor = new Sensor[polhemusActiveReceivers];
polhemusSensorRead = new SensorRead[polhemusActiveReceivers];
initPosTransform = new Transform3D[polhemusActiveReceivers];
initOriTransform = new Transform3D[polhemusActiveReceivers];
for (int n=0; n<polhemusActiveReceivers; n++)
{
polhemusSensor[n] = new Sensor(this);
polhemusSensorRead[n] = new SensorRead();
initPosTransform[n] = new Transform3D();
initOriTransform[n] = new Transform3D();
try
{
polhemus.readData();
}
catch( Exception e )
{
System.err.println( "PID: " + e.toString() );
}
getPositionTransform( n+1, initPosTransform[n] );
getOrientationTransform( n+1, initOriTransform[n] );
}
setSensitivity(0.1f);
setAngularRate(0.01f);
}

public boolean initialize()
{
for (int i=0; i<3; i++)
{
polhemusPos[i] = 0.0f;
polhemusOri[i] = 0.0f;
}
return true;
}

public void close()
{
}

public int getProcessingMode()
{
return DEMAND_DRIVEN;
}

public int getSensorCount()
{
return polhemusActiveReceivers;
}

public Sensor getSensor( int id )
{
return polhemusSensor[id];
}

public void setProcessingMode(int mode)
{
}

public void getPositionTransform(int n, Transform3D posTrans)
{
polhemusPos = polhemus.getLocation(n);
posVector.x = polhemusPos[0];
posVector.y = polhemusPos[1];
posVector.z = polhemusPos[2];
posTrans.setIdentity();
posTrans.setTranslation(posVector);
}

public void getOrientationTransform(int n, Transform3D oriTrans)
{
polhemusOri = polhemus.getRotation(n);
oriTrans.setIdentity();

// Fastrak gives azimuth, elevation and roll, which
// do not translate to Java3D X, Y and Z directly, so
// some assembly is required. Glue included.
trans.setIdentity();
trans.rotY(-Math.toRadians((double)polhemusOri[0]));
oriTrans.mul(trans);
trans.setIdentity();
trans.rotX(Math.toRadians((double)polhemusOri[1]));
oriTrans.mul(trans);
trans.setIdentity();
trans.rotZ(-Math.toRadians((double)polhemusOri[2]));
oriTrans.mul(trans);
}

public void pollAndProcessInput()
{
try
{
polhemus.readData();
}
catch( Exception e )
{
System.err.println( "PID: " + e.toString() );
}
for (int n=0; n<polhemusActiveReceivers; n++)
{
polhemusSensorRead[n].setTime(System.currentTimeMillis());
getPositionTransform(n, posTransform);
getOrientationTransform(n, oriTransform);

polhemusTransform.setIdentity();
polhemusTransform.mulInverse(initOriTransform[n]);
polhemusTransform.mul(oriTransform);

Vector3d translation = new Vector3d();
posTransform.get( translation );
translation.scale( (double)sensitivity );
polhemusTransform.setTranslation( translation );

polhemusSensorRead[n].set(polhemusTransform);
polhemusSensor[n].setNextSensorRead(polhemusSensorRead[n]);
}
}

public void processStreamInput()
{
}

public void setNominalPositionAndOrientation()
{
initialize();
for (int n=0; n<polhemusActiveReceivers; n++) {
polhemusSensorRead[n].setTime(System.currentTimeMillis());
polhemusTransform.setIdentity();
polhemusSensorRead[n].set(polhemusTransform);
polhemusSensor[n].setNextSensorRead(polhemusSensorRead[n]);
}
}

public void setSensitivity(float value)
{
sensitivity = value;
}

public float getSensitivity()
{
return sensitivity;
}

public void setAngularRate(float value)
{
angularRate = value;
}

public float getAngularRate()
{
return angularRate;
}
}



en la parte donde marca el primer error es aqui

public Sensor getSensor( int id )
{
return polhemusSensor[id];
}


hojala puedas ayudarme o alguien mas gracias