|
| |||||||||
| Tags: heap, java, memory, over, programming language, random function, stack |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| StackOverflow Error and Random function
Hello, I have a recursive function that creates a tree. Within this function, call me a method that returns a linked list of elements chosen randomly in a greater whole. The program is repeatedly on the values of trees growing. Up to a certain size I have no problem. At one time the execution stops and I have a "StackOverflowError" has a problem with the line where the function is called random. (random.nextInt (int)). I do not have any idea about this error and if you know something about it then please let me know. Thanks in advance.
__________________ www.techarena.in |
|
#2
| |||
| |||
| Re: StackOverflow Error and Random function
Hello, The stackoverflow is usually from a infinite recursion. Now depending on the version of JVM used it is possible that there is a limit more or less reachable objects (it should still be pretty huge, I put instead on the infinite loop). You have to try to verify that you return your random, it is quite probable that at one time or another he will form a loop that causes the error. |
|
#3
| |||
| |||
| Re: StackOverflow Error and Random function
Hello, I am new to java, but I have a code, I think even I had a same problem. Still check out the code and if there are some corrections to be made then correct me Code: private lstatr changemethod(int nbAtributs, int maxAttr) {
lstatr fir = null;
lstatr lstr = null;
lstatr tpatt;
Random rndm = new Random();
int kre = rndm.nextInt(maxAttr) + 1;
fir = new lstatr(kre);
lstr = fir;
int i = 1;
while (i <nbAtributs) {
kre = rndm.nextInt(maxAttr) + 1;
while (existeDeja(kre, fir)) {
kre = rndm.nextInt(maxAttr) + 1;
}
tpatt = new lstatr(kre);
lstr.setChaineSuiv(tpatt);
lstr = lstr.getChaineSuiv();
i + +;
}
return fir;
} |
|
#4
| |||
| |||
| Re: StackOverflow Error and Random function
Hello, Code: while (ext(k, first)) {
k = random.nextInt(maxAttr) + 1;
} |
|
#5
| |||
| |||
| Re: StackOverflow Error and Random function
Hello, Have a look at the below code, this might be what you need. Code: Public static int fc_rc(int i) {
if(i < 0) { return -1; / * Error * / }
else if(i ==0 | | I == 1) { return 1; }
else { return i * fc_rc(i-1); } / * Here we have the recursive call * /
}
Public static int fc_it(int i) {
if(i < 0) { return -1; / * Error * / }
int rs = 1;
while(i> 1) {
rs *= i;
i -;
}
return rs;
} |
|
#6
| |||
| |||
| Re: StackOverflow Error and Random function
Hello, See if this code may interest you. Code: Public class Hand {
static int cnt = 0;
Public static void recrv() {
cnt + +;
recrv();
}
Public static void hand(String[] args) {
try {
recrv();
} catch (StackOverflowError e) {
System.err.System.out.println("After StackOverflowError" cnt + + "Method calls ...");
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "StackOverflow Error and Random function" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Generate some quality of random number via Random Number Generation function | aMADeO! | Windows Software | 4 | 4 Weeks Ago 05:07 PM |
| Internet Script error box pops up and list a random website in the error box | Jagathi | Networking & Security | 6 | 15-07-2011 08:23 PM |
| Function for two random numbers | Zool | Software Development | 3 | 03-12-2009 12:39 PM |
| Problem in a random word function | klite | Software Development | 3 | 30-11-2009 12:49 PM |
| Random Function to Concatenate 2 strings | klite | Software Development | 3 | 14-10-2009 12:48 PM |