简体   繁体   中英

2 Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Can someone help me to solve this problem? the code: http://pastebin.com/nDG7YGk5

the full error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Stack.push(Stack.java:16) at hanukkah.input(hanukkah.java:42) at hanukkah.main(hanukkah.java:50)

I'm not using a virtual machine, just eclipse.

Thanks.

This is an infinite loop:

 while(n!=0)
 s.push(n);

The value of n isn't changing when you push it to the Stack. So it will never equal 0. You probably meant that to be an if statement (to make sure the user didn't enter 0), or to put the while loop around the scanner so that they can keep entering digits until they don't equal 0.

I think you meant to do something like:

int n = Integer.MAX_VALUE;
while (n != 0) {
   n = reader.nextInt();
   s.push(n);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM