I am new to java and have been working on a project. The project involves two files: One with student ID numbers and their answers for 10 different questions.
The second file contains a bunch of ID numbers from the first file.
The second file has id numbers for a different school.
The task is go through each line in the first file and check if the id number is the same as in the second file, if it is, then move on to the next line, and if it is not, then calculate the student score based on his answer.
I know how to calculate the total.
The question is how to check each id number and see if it is the same. I am getting null pointer exception.
My code is as follows:
public static int findWHSAvg() throws IOException
{
readData();
int count = 0;
int temp = 0;
int sum = 1;
int average = 0;
String[] ECHSid = new String[50];
String[] CitizenshipID = new String[50];
int[] stdt;
int[] answer = answerKey();
while (inScan2.hasNextLine())
{
String id1 = inScan2.next();
ECHSid[temp] = id1;
temp++;
String nextLine = inScan2.nextLine();
}
String aa = inScan.nextLine();
while (inScan.hasNextLine())
{
String id = inScan.next();
CitizenshipID[count] = id;
count++;
// if (!(isMatch(ECHSid[count], CitizenshipID[count])))
// {
// stdt = studentAns(new int[11]);
// for (int cnt = 0; cnt <= 10; cnt++)
// {
// if (answer[cnt] == stdt[cnt])
// {
// sum++;
// }
// }
// }
String nextLine = inScan.nextLine();
}
for (int a = 0; a <= count; a++)
{
boolean match = false;
for(int b = 0; b <= temp; b++)
{
if(isMatch(CitizenshipID[a], ECHSid[b]))
{
match = true;
}
}
//if not found
if(!match)
{
// stdt = studentAns(new int[11]);
// for (int cnt = 0; cnt <= 10; cnt++)
// {
// if (answer[cnt] == stdt[cnt])
// {
// sum++;
// }
// }
// average = (int)(((sum/11.0)*100.0)+0.5);
readData();
while (inScan.hasNextLine())
{
String id = inScan.next();
if (isMatch(id,CitizenshipID[a]))
{
stdt = studentAns(new int[11]);
for (int cnt = 0; cnt <= 10; cnt++)
{
if (answer[cnt] == stdt[cnt])
{
sum++;
}
}
average += (int)(((sum/11.0)*100.0)+0.5);
}
/*String nextLine = inScan.nextLine();*/
}
}
}
return average;
}
ECHSid is an array that has all the ids from the second file and CitizenshipID is an array that has all the ids from the first file.
Please help me, I get the NullPointerException and it says this for the line in this method:
at Project1.findAvg(Project1.java:338)
which is this line:
if(isMatch(CitizenshipID[a], ECHSid))
Please help me.