mayma
-
Modifié par BunoCS le 19/07/2016 à 11:30
BunoCS
Messages postés15475Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention23 avril 2024
-
19 juil. 2016 à 12:59
Bonjour,
Voilà mon erreur :java.lang.ArrayIndexOutOfBoundsException: 4, j'arrive pas à le résoudre. Merci bien pour votre aide. Voici mon code:
public class CoordinateMatrix {
private static GeometryFactory geomFact = new GeometryFactory();
private Map<Integer, Node> multiMap = new HashMap<>();
public CoordinateMatrix(File f) throws IOException {
fillMatrix(f);
}
public void fillMatrix(File f) throws IOException {
// We create a BufferReader
InputStream ips = new FileInputStream(f);
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
String Line = br.readLine();
// On récupère le tableau des identifiants
int id = 0;
int indexX = 2;
int indexY = 3;
int cat= 4;// catégorie :point de collecte ou dépot de stockage.
// On parcourt chaque ligne
while ((Line = br.readLine()) != null) {
// On parse la ligne courante
String[] tabLineTemp = Line.split(";");
System.out.println(Arrays.toString(tabLineTemp));
//On fait un test => si c'est 0 alors on crée un Point de Collecte
//Si c'est un on crée un centre de stockage
//On ajoute à la hasmap
if(Integer.parseInt(tabLineTemp[cat])==0){
DepotDeStockage d= new DepotDeStockage (Integer.parseInt(tabLineTemp[id]), indexX, indexY, 0);
}
else if(Integer.parseInt(tabLineTemp[cat])==1){
PointDeCollecte p= new PointDeCollecte (Integer.parseInt(tabLineTemp[id]), indexX, indexY, 1);
}
Node n = new Node(Integer.parseInt(tabLineTemp[id]),
Double.parseDouble(tabLineTemp[indexX])
, Double.parseDouble(tabLineTemp[indexY])
, Double.parseDouble(tabLineTemp[cat])) ;
multiMap.put(Integer.parseInt(tabLineTemp[id]), n);
}
br.close();
}
public Set<Integer> getListId() {
return multiMap.keySet();
}
public com.vividsolutions.jts.geom.Point getPoint(int id) {
Node n = multiMap.get(id);
if(n == null){
return null;
}
return geomFact.createPoint(new Coordinate(n.getX(), n.getY()));
}
public Collection<Node> getListNodes(){
return multiMap.values();
}
public static void main(String[] args) throws IOException {
File f = new File(CoordinateMatrix.class.getResource("/data/idf/com_idf_pt_xy.csv").getPath());
CoordinateMatrix cM = new CoordinateMatrix(f);
Set<Integer> Lid = cM.getListId();
System.out.println("---------------------------------"); for (int i =
0; i < Lid.size(); i++) {
System.out.print(Lid.toArray()[i] + ";");
} System.out.println("");
System.out.println("---------------------------------");
com.vividsolutions.jts.geom.Point p = cM.getPoint(77283);
System.out.println("Les coordnnées du point qui a l'id 77283 sont : " + p);
}
}
EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ICI
Bonjour,
Merci pour votre réponse, en fait j'ai un tableau de taille 5 et pour le moment j'ai pas besoin de la 2éme case c'est pour cela j'ai pas déclaré l'id.