I made a function that is reading a file and putting each line in an array of size 8 which is then adding that array to an arraylist. I am then taking each value per line and trying to pass them into functions but for some reason I am getting null pointers exceptions. Is it because I am using an arraylist? The functions themselves are working if I pass the parameters through the console. I am trying to take the Strings and pass them to a function. example: dep(eachLine.get(0)[1]) does not work. I even created get functions for each slot and put them in a loop with a nested loop to try and pull out the values and it's not working.
public void readFile(String x) throws IOException{
File file = new File(x);
BufferedReader br = new BufferedReader(new FileReader(file));
String str="";
while((str = br.readLine())!= null)
{
String line[] = new String[8];
int count =0;
StringTokenizer token = new StringTokenizer(str,",");
while(token.hasMoreTokens())
{
line[count]= token.nextToken();
count++;
}
eachLine.add(line);
}
}
public int getAccountInt(int i){
//readFile(x);
return Integer.parseInt(eachLine.get(i)[4]);
}
public String getName(int i){
//readFile(x);
return eachLine.get(i)[1];
}
public int getSSNUM(int i){
//readFile(x);
return Integer.parseInt(eachLine.get(i)[2]);
}
public String getAddress(int i){
//readFile(x);
return eachLine.get(i)[3];
}
public int getCCAccountInt(int i){
//readFile(x);
return Integer.parseInt(eachLine.get(i)[6]);
}
public double getDepositInt(int i){
//readFile(x);
return Double.parseDouble(eachLine.get(i)[5]);
}
public double getCreditInt(int i){
//readFile(x);
return Double.parseDouble(eachLine.get(i)[7]);
}
public String getCommand(int i){
//readFile(x);
return eachLine.get(i)[0];
}
this is in main
x.readFile("today.txt"); System.out.println(x.eachLine.get(0)[4]);
for(int i =0;i<x.eachLine.size();i++){
String f = x.getCommand(i);
String s = x.getName(i);
int a = x.getSSNUM(i);
String t = x.getAddress(i);
int b = x.getAccountInt(i);
double d = x.getDepositInt(i);
int c = x.getCCAccountInt(i);
double e = x.getCreditInt(i);
if(f.equals("ONA")){
db.createAll(s, a, t, b, d, c, e);
}
}