Chris Keli:
Así que estoy tratando de leer en un archivo y obtener partes de ella, pero me siguen dando el error anterior en la línea
arrayLocations [i] = new Ubicación (Double.parseDouble (Xarray [1]), Double.parseDouble (Xarray [2]))
int total;
BufferedReader bfr;
String lineObtained = null;
Location[] arrayLocations = null;
try {
bfr = Files.newBufferedReader(path);
lineObtained = bfr.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
String split = lineObtained.split("POSTAL_OFFICE")[1];
String[] y = split.split(" ");
double xCoord = Double.parseDouble(y[0].trim());
double yCoord = Double.parseDouble(y[1].trim());
Location postOffice = new Location(xCoord, yCoord);
String split1 = lineObtained.split("WORKER_ADDRESS")[1];
String[] y1 = split.split(" ");
double xCoord1 = Double.parseDouble(y1[0].trim());
double yCoord1 = Double.parseDouble(y1[1].trim());
Location home = new Location(xCoord, yCoord);
split = lineObtained.split("POSTAL_ADDRESSES")[1].trim();
String[] splits = split.split("\\r?\\n");
for(int i = 0; i < splits.length; i++) {
String[] xArray = splits[i].split(" ");
arrayLocations[i] = new Location(Double.parseDouble(xArray[1]), Double.parseDouble(xArray[2]));
}
PWPInstance instance = new PWPInstance(total, arrayLocations, postOffice, home, random);
return instance;
Federico klez Culloca:
Usted declaró arrayLocation
que null
nunca se ha inicializado.
Es posible que desee algo así como
Location[] arrayLocations = new Location[splits.length];
Justo antes de que el bucle (sin necesidad de declarar que al inicio del procedimiento, declarar que cuando es necesario), ya que es el primer lugar que lo usa y el lugar que sabe lo grande que las necesidades de matriz que sean.