I am attempting to calculate Z_Scores in Java. However, I am new to programming and Java and cannot seem to figure out what is wrong. I keep getting a null pointer exception. Can anyone enlighten me as to what I am doing wrong. I am getting the exception at line 80 in bold. For whatever reason it doesn't like the object I am using. Here is my source code:
public class Z_score {
double Mean []=new double[10];
double SD []=new double[10];
Z_Expert [] Z_All;
public Z_Expert[] getZ_All() {
return Z_All;
}
public void setZ_All(Z_Expert[] z_All) {
Z_All = z_All;
}
public double[] getMean() {
return Mean;
}
public double[] getSD() {
return SD;
}
public void setSD(double[] sD) {
SD = sD;
}
public void setMean(double[] mean) {
Mean = mean;
}
public void Z_Calc(Expert_Score...args){
Z_score r = new Z_score();
Expert_Score[] All_users=args;
double sum = 0;
double v = 0;
double t []= new double[10];
double h []= new double[10];
double a []= new double[10];
double [] w=new double[10];
double [] s=new double[10];
Z_Expert[] All_user = new Z_Expert[All_users.length];
for(int j=0;j<10;j++){
for(int i=0;i<All_users.length;i++){
Expert_Score x=All_users[i];
double [] y=x.getExpert_Scores();
sum=sum+y[j];
}
t[j]=(sum/All_users.length);
sum=sum-t[j]*All_users.length;
}
r.setMean(t);
for (int k=0;k<10 ;k++){
for(int l=0;l<All_users.length;l++){
Expert_Score z=All_users[l];
double [] q=z.getExpert_Scores();
v=v+(q[k]-t[k])*(q[k]-t[k]);
}
a[k]=(v/All_users.length);
v=v-a[k]*All_users.length;
}
r.setSD(a);
s=r.getMean();
w=r.getSD();
for (int m=0;m<10;m++){
for(int n=0;n<All_users.length;n++){
Expert_Score z=All_users[n];
int a2=z.getID();
double [] q=z.getExpert_Scores();
h[m]=(q[m]-s[m])/w[m];
Z_Expert a1 = new Z_Expert(a2, h);
All_user[n]=a1;
}
r.setZ_All(All_user);
}
}
public void print(Z_score x) {
Z_Expert [] g=x.getZ_All();
**for(int p=0;p<g.length;p++){**
Z_Expert e=g[p];
int sum=1;
double [] f=e.getExpert_Scores();
System.out.println("ID: "+e.getID());
for(int o = 0;o<10;o++){
System.out.print("Domain "+sum+": "+f[o]+ " ");
sum++;
}
System.out.println();
System.out.println();
}
}
public static void main(String[] args){
double p1[] = {1,2,5,7,5,6,6,8,9,10};
double p2[] = {4,3,4,3,4,1,2,3,1,5};
double p3[] = {10,2,6,4,5,6,7,8,9,10};
Expert_Score x = new Expert_Score(1, p1);
Expert_Score y = new Expert_Score(2, p2);
Expert_Score z = new Expert_Score(3, p3);
Z_score scrCalc = new Z_score();
scrCalc.Z_Calc(x,y,z);
scrCalc.print(scrCalc);
}
}
Thanks in advance!