I keep getting a null pointer on this assignment and I figure that I can't fix it because my logic is deeply flawed somewhere.
Here is the code that I have:
import java.util.*;
import java.io.*;
public class Project1 {
public static class MapPoint {
private String elevation;
private String lattitude;
private String longitude;
public MapPoint() {
elevation = "";
lattitude = "";
longitude = "";
}
//set
public void setElevation(String s) {
elevation = s;
}
public void setLattitude(String s) {
lattitude = s;
}
public void setLongitude(String s) {
longitude = s;
}
//get
public String getElevation() {
return elevation;
}
public String getLattitude() {
return lattitude;
}
public String getLongitude() {
return longitude;
}
}
public static void main(String[] args) {
try {
String numRows = "";
String numCols = "";
boolean status = true;
File input = new File("input.txt");
Scanner infile = new Scanner(input);
while(status == true) {
numRows = infile.next();
numCols = infile.next();
int numRowsInt = Integer.parseInt(numRows);
int numColsInt = Integer.parseInt(numCols);
if(numRowsInt == 0 && numColsInt == 0) {status = false;}//kills the loop when end of file signifier reached
else {
MapPoint[][] myMap = new MapPoint[numRowsInt][numColsInt];
for(int i = 0; i < numRowsInt; i++) {
for(int j = 0; j < numColsInt; j++) {
MapPoint mapPoints = new MapPoint();
mapPoints.setElevation(infile.next());
mapPoints.setLattitude(infile.next());
mapPoints.setLongitude(infile.next());
}
}
//test loop
for(int i = 0; i < numRowsInt; i++) {
for(int j = 0; j < numColsInt; j++) {
System.out.println(myMap[i][j].getElevation() + " " + myMap[i][j].getLattitude() + " " + myMap[i][j].getLongitude());
}
}
}
status = false;
}
//System.out.println(numRows);
//System.out.println(numCols);
}
catch(FileNotFoundException e) {
System.out.println("There is no file present.");
}
catch(ArrayIndexOutOfBoundsException f) {
f.printStackTrace();
f.getMessage();
f.toString();
}
}
}
Any help would be appreciated, and explanation on why my techniques is wretched is welcome.