我在这里的错误是在我的方法调用和类的创建其他类的构造函数的无限或接近无限循环。我的程序试图做的是根据实际统计数据半随机生成调查结果。我非常感谢不仅在这里发生了什么问题的一些洞察力。但是关于如何防止这种情况发生的一些建议和指导以及我自己分析错误信息的方法。我了解了一些工作,但就像我在下面陈述的那样,我对大学新生进行编程是新手,所以编程对我来说是新的。先谢谢了,并对我以前的帖子感到遗憾,我想我会花时间给你们一个合适的。stackoverflowror null
即时通讯新编程这是我的第二个项目我做了我自己的所以即时通讯抱歉,如果它不是最好的。
这是我的测试类:
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);
}
}
}
}
统计类:
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++;
}
和概率类:
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;
}
这是唯一真正的重要组成部分,其中环exsists的其余代码不需要上传。
在上传我的错误消息在本网站上它不接受它作为代码插入代码,然后它不会让我提交消息后,所以我会上传代码其他软件,并链接它。
http://forum.overdosed.net/index.php/topic/56608-this-is-unimportant/
但我不知道多久,该论坛将让我保持这个职位有> <
您没有向我们展示'Statistics'的构造函数,这是我怀疑问题的地方。 – 2012-03-11 07:51:17
AHH抱歉持有 – 2012-03-11 07:53:05