Applet: StackOverflowError when calling readObject()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • verteidi
    New Member
    • Feb 2008
    • 4

    #1

    Applet: StackOverflowError when calling readObject()

    Hello everyone,
    I have been searching this forum for a solution to my problem, but unfortunately couldn't find anything so far. It would be very kind if you could take a look at this.
    I am trying to read an object, that I have saved before in a file called "eco.net", in an applet with the readObject() method:
    [CODE=java]import java.applet.*;
    import java.io.*;

    public class TestApplet extends Applet
    {
    public void init()
    {
    try{
    FileInputStream fis = new FileInputStream ("eco.net");
    ObjectInputStre am ois = new ObjectInputStre am(fis);

    BioNet bioNet = (BioNet) ois.readObject( );
    ois.close();
    } catch (IOException e) {
    e.printStackTra ce();
    } catch (ClassNotFoundE xception e) {
    e.printStackTra ce();
    }
    }
    }
    [/CODE]
    The command-line output of this is:
    [CODE=error]java.lang.Stack OverflowError
    at java.io.ObjectI nputStream$Bloc kDataInputStrea m.readByte(Obje ctInputStream.j ava:2718)
    at java.io.ObjectI nputStream.read Handle(ObjectIn putStream.java: 1428)
    at java.io.ObjectI nputStream.read ClassDesc(Objec tInputStream.ja va:1490)
    at java.io.ObjectI nputStream.read OrdinaryObject( ObjectInputStre am.java:1732)
    at java.io.ObjectI nputStream.read Object0(ObjectI nputStream.java :1329)
    at java.io.ObjectI nputStream.read Array(ObjectInp utStream.java:1 667)
    at java.io.ObjectI nputStream.read Object0(ObjectI nputStream.java :1323)
    at java.io.ObjectI nputStream.defa ultReadFields(O bjectInputStrea m.java:1945)
    at java.io.ObjectI nputStream.read SerialData(Obje ctInputStream.j ava:1869)
    at java.io.ObjectI nputStream.read OrdinaryObject( ObjectInputStre am.java:1753)
    at java.io.ObjectI nputStream.read Object0(ObjectI nputStream.java :1329)
    at java.io.ObjectI nputStream.defa ultReadFields(O bjectInputStrea m.java:1945)
    ...
    [/CODE]
    These kind of errors continue for more than 1000 lines.
    If I try to read the same object in a normal application, this works flawlessly:
    [CODE=java]import java.io.*;

    public class Test
    {
    public static void main(String[] args)
    {
    try{
    FileInputStream fis = new FileInputStream ("eco.net");
    ObjectInputStre am ois = new ObjectInputStre am(fis);

    BioNet bioNet = (BioNet) ois.readObject( );
    ois.close();
    } catch (IOException e) {
    e.printStackTra ce();
    } catch (ClassNotFoundE xception e) {
    e.printStackTra ce();
    }
    }
    }
    [/CODE]
    I made sure that the classes I am creating the object "eco.net" from implement the Serializable interface, as I read that this is likely to cause problems.
    A bit more information about the object that I am trying to read:
    I am trying to create a Java-representation of a biochemical network "BioNet". This uses the classes "Compound" and "Reaction", which are themselves interlinked. Please tell me if it would help you to see the whole code (it is quite a lot, that's why I didn't post it already). The actual writing of the object in a file is done with this code:
    [CODE=java]import java.io.*;

    public class BuildBioNet {

    public static void main(String[] args) {
    try {

    FileOutputStrea m fos = new FileOutputStrea m("eco.net");
    ObjectOutputStr eam oos = new ObjectOutputStr eam(fos);

    BioNet eco = new BioNet();
    eco.buildFromFi le("ecoInfo.ref ","ecoBioNet.tx t");

    oos.writeObject (eco);

    // Flush and close the ObjectOutputStr eam.
    oos.flush();
    oos.close();
    } catch (IOException e) {
    e.printStackTra ce();
    }
    }
    }
    [/CODE]
    The file size of "eco.net" is 325kB, if this is of any importance. I am using Java version 1.5.0.
    Thank you very very much,any help is appreciated - this problem is driving me mad for days already.
    Regards,
    Kai
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    I would dump the applet and try to get this working in a standalone application -- it will be easier to debug. Try using a smaller file. Also try raising your max memory: see options -XMs and -XMx: http://java.sun.com/javase/6/docs/te...dows/java.html

    Comment

    • verteidi
      New Member
      • Feb 2008
      • 4

      #3
      Thank you for your quick answer. I tried raising the maximum memory to 120Mb without effect, I still get the same error message for the applet. My goal is to create a web-tool for external users that work with the biochemical network (a graph creation and manipulation tool), so I would like to keep the applet. It is already working as a standalone application. I have been working with objects of similar size already and it worked without problems, I just can't figure out, why it is not working with this one. Thank you again!

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by verteidi
        Thank you for your quick answer. I tried raising the maximum memory to 120Mb without effect, I still get the same error message for the applet. My goal is to create a web-tool for external users that work with the biochemical network (a graph creation and manipulation tool), so I would like to keep the applet. It is already working as a standalone application. I have been working with objects of similar size already and it worked without problems, I just can't figure out, why it is not working with this one. Thank you again!
        Did you also try to increase the stack size? (use the -XMs option). Graphs
        are read recursively, i.e. when a node is connected to another node (through an
        edge) the ObjectInputStre am calls itself recursively to read that other node.

        kind regards,

        Jos

        Comment

        • verteidi
          New Member
          • Feb 2008
          • 4

          #5
          Thank you! I already suspected it to be a recursion problem, but couldn't connect it with my network. I will try to change its structure again, so perhaps I can avoid deep recursion. It became a lot clearer to me now.
          By the way, changing the stack size was without effect, as well.
          Have a nice day still and thank you again!

          Comment

          • verteidi
            New Member
            • Feb 2008
            • 4

            #6
            It worked! I separated the processes 'creating and reading the BioNet' and 'connecting the nodes'. Only after retrieving the "eco.net" object I am establishing the final structure. No StackOverflowEr ror any more.
            Thank you all for the final clue and all the help, now I can finally sleep without nightmares of Stacks falling on my head again.

            Comment

            Working...