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 7614719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:28:30+00:00 2026-05-31T02:28:30+00:00

The error i am having here is a infinite or near infinite loop in

  • 0

The error i am having here is a infinite or near infinite loop in my method calls and class’s creating other class’s constructors. What my program is trying to do is semi-randomly generate survey results based off actual statistics. I would highly appreciate not only some insight in whats going wrong here. But some advice and pointers on how to prevent this from happening and ways to analyze the error messages by myself. I get how some of the work but like i stated below i am new to programming im a freshman in college so programming is new to me. Thanks in advance and sorry for my previous post, thought i would take the time to give you guys an appropriate one.

Im new to programming this is my 2nd project ive done on my own so im sorry if its not the best.

This is my Test class:

 public Tester()
{
    randomGenerator = new Random();
    probability = new Probability();
    stats = new Statistics();
    double chance = randomGenerator.nextDouble();
    double gender = probability.getProbabilityOfMale();
    if(chance > gender)
    {
        male = false;
        stats.incrementFemale();
    }else{
        male = true;
        stats.incrementMale();
    }
    age = randomGenerator.nextInt(49)+16;
    int range = stats.getNumberOfQuestion();
    for(int i=0;i<range;i++)
    {
       probabilities = probability.probOfAnswer(i);
       answers = probability.getAnswers(i);
       chance = randomGenerator.nextDouble();
       int size = probabilities.size();
       for(int j=0;j<size;j++)
       {
         double qTemp = chance - probabilities.get(j);
         if(qTemp <= 0.0)
         {
             Answer aTemp = answers.get(j);
             aTemp.incrementCounter();
             answers.set(j,aTemp);
          }
       }
    }
}

Statistics class:

 public ArrayList<Answer> getAnswers(int index)
{
    temp = survey.getAnswers(index);
    return temp;
}

public int getMale()
{
    return male;
}

public int getFemale()
{
    return female;
}

public int getNumberOfQuestion()
{
    return numberOfQuestion;
}

public void incrementNumberOfQuestion()
{
    numberOfQuestion++;
}

public void incrementMale()
{
    male++;
}

public void incrementFemale()
{
    female++;
}

and probability class:

 public Probability()
{
    stats = new Statistics();
    probOfAnswer = new ArrayList<Double>(0);
}

public ArrayList<Double> probOfAnswer(int index)
{               
    temp = stats.getAnswers(index);
    int size = temp.size();
    for(int i=0;i<size;i++)
    {
        aTemp = temp.get(i);
        for(int j=0;j<size;j++)
        {
            Answer aTemp = temp.get(j);
            sum += (double)aTemp.getCounter(); 
        }
        double number = (double)aTemp.getCounter();
        probOfAnswer.add(number/sum);
        sum = 0;

    }
    return probOfAnswer;
}

public ArrayList<Answer> getAnswers(int index)
{
    temp = stats.getAnswers(index);
    return temp;
}

public ArrayList<Double> getProbofAnswer()
{
    return probOfAnswer;
}

public void probabilityOfMale()
{        
    double male = (double)stats.getMale();
    double female = (double)stats.getFemale();
    probabilityOfMale = male / (male + female);
}

public double getProbabilityOfMale()
{
    return probabilityOfMale;
}

These are the only real important parts where the loop exsists the rest of the code is not needed to be uploaded.

Im having difficulty uploading my error message on this site its not accepting it as code in the code insert, then it wont let me submit the message afterwards so im going to upload the code elseware and link it.

http://forum.overdosed.net/index.php/topic/56608-this-is-unimportant/

But i dont know how long that forum will let me keep that post there ><

  • 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-31T02:28:31+00:00Added an answer on May 31, 2026 at 2:28 am
    at Question.<init>(Question.java:17)
    at Survey.addQuestion(Survey.java:23)
    at Statistics.<init>(Statistics.java:52)
    at Question.<init>(Question.java:17)
    at Survey.addQuestion(Survey.java:23)
    at Statistics.<init>(Statistics.java:52)
    at Probability.<init>(Probability.java:19)
    

    You need to check why Question is creating Statistics object and again Statistics is trying to create Question object leading to infinite recursion. As the line numbers are given you can take a look at corresponding lines.

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

Sidebar

Related Questions

here is the part if having error. Fatal error: Using $this when not in
I'm having an error where I am not sure what caused it. Here is
I am updating my class Nesty so it's infinite but I'm having a little
I'm having an error while loading an mp3 player, here is what I getting
I am creating a mine sweeper program in java for school, and am having
I don't know why I'm having this error. Here is the code where i
Having a problem here with creating a child window with c++ and win32 api.
I am having error after error trying to upload and resize images to s3
For some reason I'm having trouble getting my program to run a while loop.
I`m having the following error . Why am I having this error and how

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.