Skip to content
Advertisement

java, OutOfMemoryError: Java heap space

This class is designed to determine the language of a text; the user has to enter 4 text in english, danish, italian and latin, and then the text whose language he wants to determine. The console says

JavaScript

I use eclipse, in Run Configurations – Arguments I wrote -Xms2g-Xmx3g. I don’t understand where is the problem.

The code is

JavaScript

Advertisement

Answer

This line throws the exception:

JavaScript

why? well, your function pow(a, b) is correct but the n variable is a bit off. You are reading it from there:

JavaScript

This will give you the ascii code of the character you enter in the console, and not the number. If you write “1”, then n will be 49, and pow(27, 49) is way too much.

To simply read the input of the user, you should try to use java.util.Scanner instead, to get the number that the user inputs.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement