7
我想使每个类的两个类都有另一个类的实例化,但是需要一个java.lang.StackOverFlowError
。第一类看起来像下面StackOverFlow类错误
public class ReverseGPA {
GPpredictor gp_predictor = new GPpredictor(); //This is the line that causes error
double CURRENT_CREDITS;
double FUTURE_CREDITS;
double CUM_GPA;
double DESIRED_GPA;
double NEW_GRADE_POINT;
int ROUNDED_GRADE_POINT;
double NEW_GPS;
}
而其他类看起来像这样
public class GPpredictor {
ReverseGPA rev_gpa = new ReverseGPA(); //This is the line that causes error
ArrayList<String> arrayCourseName = new ArrayList<>();
ArrayList<Integer> arrayCourseCredit = new ArrayList<>();
ArrayList<String> arrayCourseGrade = new ArrayList<>();
int COURSES;
int CREDIT;
String COURSENAME;
//For predicting purposes
int GRADE;
}
我把它喜欢这样,因为我需要使用从类ReverseGPA方法在课堂GPpredictor使用(我需要使用等级分,通过使用getter方法)
将是任何意见非常感谢,并帮助
你好,非常感谢你的快速回复!但是,我有这个问题。 ReverseGPA类有一个调用GPpredictor方法的方法。 GPpredictor的方法需要ReverseGPA值。那么解决方案是创建每个类的实例否?我错过了什么吗?非常感谢您的回答,抱歉,您的时间不够 – Adam
@ user3764392:是的,我已经告诉过您应该做什么。您无法在每个类中创建两个实例,因此请至少将一个实例传递给另一个实例。 –
非常感谢,解决了这个问题! – Adam