1
I have the following code:
class Main {
public static void main(String[] args) {
Lista chamar = new Lista();
String[] vetor = {"Palavra", "Letra"};
chamar.adicionar(vetor);
}
}
class Lista {
ArrayList<String> lista;
public Lista() {
lista = new ArrayList<>();
} public void adicionar(String[] vetor) {
int i = 0;
while (i < vetor.length) {
lista.add(vetor[i]);
i++;
}
}
}
When I run, the error "Outofmemoryerror: Java heap space" appears, I wonder how to fix it.
This error is independent of your code: it depends on how Java runs. How you are running this code?
– Leonel Sanches da Silva
Debugging by Netbeans.
– ptkato
this code compiles?? your constructor is wrong.. I don’t think that’s the code you’re running.
– Math
Yeah, compile it, @Math.
– ptkato
@Patrick man, I opened the IDE and here does not compile, missing the
()
in his builder– Math
Oh yes, I forgot that detail.
– ptkato
Okay, I fixed here and I circled, and it didn’t burst the memory. There’s nothing more divergent than what you posted and what you’re running from?
– Math
No, it might be the computer, because isn’t it always that this error happens? I am using a Windows 8 64bit on a pc with 1GB of RAM.
– ptkato