Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3222652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:00:57+00:00 2026-05-17T16:00:57+00:00

I am attempting to calculate Z_Scores in Java. However, I am new to programming

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:00:57+00:00Added an answer on May 17, 2026 at 4:00 pm

    Ok, you’ve got some weird things going on here.

    Ultimately you need to call setZ_All on any instance of Z_score before you try to print it. This will initialize the Z_All variable such that it won’t be null anymore.

    Looks to me like the root of the problem is in the Z_Calc(Expert_Score…args) method. That method is an instance method of Z_score, but you’re instantiating a new Z_score on the first line of that method (32):

    Z_score r = new Z_score();
    

    You then use this r variable throughout the method, but because r is a separate instance of the Z_score class nothing you do to it really matters within the context of your main method. So even though setZ_All gets called on the r instance, it doesn’t actually affect the instance created on line 103 in your main method.

    Long story short, try replacing all references to ‘r’ with ‘this’ in your Z_Calc method and see if that gets you any further. I have a feeling there are some more errors, but that should help with this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to C# world. I am attempting to calculate time taken by
I am attempting to create a mosaic of images in Java. I calculate the
Attempting to print out a list of values from 2 different variables that are
When attempting to call functions in math.h , I'm getting link errors like the
In attempting to use the Performance Tools on an ASP.NET website I'm getting various
I'm attempting to calculate the average color of an image in Scala, where average
In OpenGL in Delphi, I am attempting to calculate how much of a scene
I am getting expected ClassVerifyErrors when attempting to load a class i have generated
When attempting to calculate the keyword density of a single keyword in a string
I'm attempting to make a tank game in java in the vein of Scorched

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.