Results 1 to 3 of 3
  1. #1
    cele1989 is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default GSON causing stack overflow error?

    When I execute the code beneath in Netbeans I get perfect result. Getting the 2 lines in comment, out of comment resulting in a Stack overflow error:
    Exception in thread "main" java.lang.StackOverflowError
    at java.util.ArrayList.get(
    at java:354)
    at java:318)

    Why is this happening and how can I fix it?

    import java.util.List;
    import persist.Reeks;

    public class TestHibernate {

    public static void main(String[] args) {
    List<Reeks> reeksen;
    try {
    reeksen = Functionalities.alleReeksenOpvragen();
    for (int i = 0; i < reeksen.size(); i++) {
    System.out.println("reeks: " + reeksen.get(i).getId() + " - " + reeksen.get(i).getNaam() + " - " + reeksen.get(i).getDatumuitgave());
    //String json = new Gson().toJson(reeksen);

    } catch (Exception e) {

  2. #2
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Rep Power

    Default Re: GSON causing stack overflow error?

    Well, you're out of Stack space. Try running with -Xms256M -Xmx512M flags (or larger if you have to) to the VM. (min-stack 256MB, max-stack 512MB), etc.

    Edit: I don't use netbeans, so can't help as to where the VM flags are set.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: GSON causing stack overflow error?

    That increases the heap, and has nothing to do with the stack.

    The OP's code is going into a recursive loop.
    Since it's JSON I suspect there are recursive dependencies in the objects they are trying to convert into a JSON string.
    That is class A has an attribute referring to class B, which also has an attribute referring back to class A.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Stack Overflow?
    By kyle_maddisson in forum New To Java
    Replies: 5
    Last Post: 11-17-2011, 11:49 AM
  2. Gui problem and stack overflow error
    By zaricpp in forum Advanced Java
    Replies: 5
    Last Post: 06-03-2011, 09:54 AM
  3. Replies: 1
    Last Post: 03-17-2010, 05:25 AM
  4. Stack Overflow work around?
    By Coukapecker in forum New To Java
    Replies: 2
    Last Post: 03-14-2010, 08:49 PM
  5. Graphics2D: stack overflow error
    By rosh72851 in forum New To Java
    Replies: 11
    Last Post: 10-15-2008, 09:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts