Je reçois cette erreur:
public static Map<Integer, Celula> descompilarMapaData(Mapa mapa, String dData) {
Map<Integer, Celula> celulas = new TreeMap<Integer, Celula>();
for (int f = 0; f < dData.length(); f += 10) {
String CellData = dData.substring(f, f + 10);
List<Byte> celulaInfo = new ArrayList<Byte>();
for (int i = 0; i < CellData.length(); i++)
celulaInfo.add((byte) getNumeroPorValorHash(CellData.charAt(i)));
int caminhavel = (celulaInfo.get(2) & 56) >> 3;// 0 = nao, 1 = meio, 4 = sim
boolean linhaDeVisao = (celulaInfo.get(0) & 1) != 0;
int layerObject2 = ( (celulaInfo.get(0) & 2) << 12) + ( (celulaInfo.get(7) & 1) << 12) + (celulaInfo.get(8) << 6)
+ celulaInfo.get(9);
boolean layerObjeto2Interac = ( (celulaInfo.get(7) & 2) >> 1) != 0;
int objeto = (layerObjeto2Interac ? layerObject2 : -1);
celulas.put(f / 10, new Celula(mapa, f / 10, caminhavel != 0, linhaDeVisao, objeto));
}
return celulas;
3 Réponses :
Le problème est avec les limites d'itération: sauf si p> ddata.length () code> est divisible par 10, cela ira déterrer des limites. Pour illustrer, l'extrait ci-dessous essaiera de lire 0-10 et 10-20, même si les limites de la matrice imaginaire ne sont que de 0 à 15. p> for (int f = 0; f < dData.length(); f += 10) {
int upperBound = min(f + 10, dData.length());
String CellData = dData.substring(f, upperBound));
merci pour la réponse :)
i Mettez le code: P>
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at estaticos.Criptografador.descompilarMapaData(Criptografador.java:152)
at variables.Mapa.<init>(Mapa.java:1306)
at estaticos.GestorSQL.CARREGAR_MAPAS(GestorSQL.java:696)
at estaticos.MundoDofus.criarServer(MundoDofus.java:1398)
at estaticos.VrauEMU.main(VrauEMU.java:130)
public static Map<Integer, Celula> descompilarMapaData(Mapa mapa, String dData) {
Map<Integer, Celula> celulas = new TreeMap<Integer, Celula>();
//changes are here
for (int f = 0; f <= dData.length() - 10; f += 10) {
String CellData = dData.substring(f, f + 10);
List<Byte> celulaInfo = new ArrayList<Byte>();
for (int i = 0; i < CellData.length(); i++)
celulaInfo.add((byte) getNumeroPorValorHash(CellData.charAt(i)));
int caminhavel = (celulaInfo.get(2) & 56) >> 3;// 0 = nao, 1 = meio, 4 = sim
boolean linhaDeVisao = (celulaInfo.get(0) & 1) != 0;
int layerObject2 = ((celulaInfo.get(0) & 2) << 12) + ((celulaInfo.get(7) & 1) << 12) + (celulaInfo.get(8) << 6)
+ celulaInfo.get(9);
boolean layerObjeto2Interac = ((celulaInfo.get(7) & 2) >> 1) != 0;
int objeto = (layerObjeto2Interac ? layerObject2 : -1);
celulas.put(f / 10, new Celula(mapa, f / 10, caminhavel != 0, linhaDeVisao, objeto));
}
return celulas;
}
Try this I think it would work for you.