我在這裏的錯誤是在我的方法調用和類的創建其他類的構造函數的無限或接近無限循環。我的程序試圖做的是根據實際統計數據半隨機生成調查結果。我非常感謝不僅在這裏發生了什麼問題的一些洞察力。但是關於如何防止這種情況發生的一些建議和指導以及我自己分析錯誤信息的方法。我瞭解了一些工作,但就像我在下面陳述的那樣,我對大學新生進行編程是新手,所以編程對我來說是新的。先謝謝了,並對我以前的帖子感到遺憾,我想我會花時間給你們一個合適的。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