java overflow_java stackoverflow error

private Vector get_line(location from, location to) {

location nextLoc = new location();

Vector loc = new Vector();

Random r = new Random();

if(to.r == from.r && to.c == from.c) {

return(loc);

} else {

if(to.r > from.r && to.c > from.c) {

nextLoc.r = from.r + 1;

nextLoc.c = from.c + 1;

} else if(to.r < from.r && to.c < from.c) {

nextLoc.r = from.r - 1;

nextLoc.c = from.c - 1;

} else if(to.r < from.r && to.c > from.c) {

nextLoc.r = from.r - 1;

nextLoc.c = from.c + 1;

} else if(to.r > from.r && to.c < from.c) {

nextLoc.r = from.r + 1;

nextLoc.c = from.c - 1;

} else if(to.r == from.r && to.c > from.c) {

if(r.nextInt(2) == 0) {

nextLoc.r = from.r + 1;

} else {

nextLoc.r = from.r - 1;

}

nextLoc.c = from.c + 1;

} else if(to.r == from.r && to.c < from.c) {

if(r.nextInt(2) == 0) {

nextLoc.r = from.r + 1;

} else {

nextLoc.r = from.r - 1;

}

nextLoc.c = from.c - 1;

} else if(to.r < from.r && to.c == from.c) {

nextLoc.r = from.r - 1;

if(r.nextInt(2) == 0) {

nextLoc.c = from.c + 1;

} else {

nextLoc.c = from.c - 1;

}

} else if(to.r > from.r && to.c == from.c) {

nextLoc.r = from.r + 1;

if(r.nextInt(2) == 0) {

nextLoc.c = from.c + 1;

} else {

nextLoc.c = from.c - 1;

}

}

loc.add(nextLoc);

return(get_line(nextLoc,to)); //stack overflow error occurs here.

}

}


版权声明:本文为weixin_39540725原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。