473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. import java.applet.*;
  2. import java.io.*;
  3.  
  4. public class TestApplet extends Applet
  5. {
  6.      public void init()
  7.      {
  8.          try{
  9.             FileInputStream fis = new FileInputStream("eco.net");
  10.             ObjectInputStream ois = new ObjectInputStream(fis);
  11.  
  12.             BioNet bioNet = (BioNet) ois.readObject();
  13.             ois.close();
  14.         } catch (IOException e) {
  15.             e.printStackTrace();
  16.         } catch (ClassNotFoundException e) {
  17.             e.printStackTrace();
  18.         }
  19.      }
  20. }
  21.  
The command-line output of this is:
Expand|Select|Wrap|Line Numbers
  1. java.lang.StackOverflowError
  2.         at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2718)
  3.         at java.io.ObjectInputStream.readHandle(ObjectInputStream.java:1428)
  4.         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1490)
  5.         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
  6.         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
  7.         at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1667)
  8.         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323)
  9.         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)
  10.         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869)
  11.         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
  12.         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
  13.         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945)
  14. ...
  15.  
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:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Test
  4. {
  5.      public static void main(String[] args)
  6.      {
  7.          try{
  8.             FileInputStream fis = new FileInputStream("eco.net");
  9.             ObjectInputStream ois = new ObjectInputStream(fis);
  10.  
  11.             BioNet bioNet = (BioNet) ois.readObject();
  12.             ois.close();
  13.         } catch (IOException e) {
  14.             e.printStackTrace();
  15.         } catch (ClassNotFoundException e) {
  16.             e.printStackTrace();
  17.         }
  18.      }
  19.  
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:
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class BuildBioNet {
  4.  
  5.     public static void main(String[] args) {
  6.         try {
  7.  
  8.             FileOutputStream fos = new FileOutputStream("eco.net");
  9.             ObjectOutputStream oos = new ObjectOutputStream(fos);
  10.  
  11.             BioNet eco = new BioNet();
  12.             eco.buildFromFile("ecoInfo.ref","ecoBioNet.txt");
  13.  
  14.             oos.writeObject(eco);
  15.  
  16.             // Flush and close the ObjectOutputStream.
  17.             oos.flush();
  18.             oos.close();
  19.         } catch (IOException e) {
  20.             e.printStackTrace();
  21.         }
  22.     }
  23. }
  24.  
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
Feb 1 '08 #1
5 3519
BigDaddyLH
1,216 Expert 1GB
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
Feb 1 '08 #2
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!
Feb 1 '08 #3
JosAH
11,448 Expert 8TB
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 ObjectInputStream calls itself recursively to read that other node.

kind regards,

Jos
Feb 1 '08 #4
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!
Feb 1 '08 #5
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 StackOverflowError 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.
Feb 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Asad Khan | last post by:
I have the following method inside I class, public boolean equals(Object o) { return (this.equals(o)); } but when i call this method by "foo.equals(bum)" where foo and bum are some objects,...
0
by: SubbaRao Karanam | last post by:
When I click the Button in Applet , I want it open a Dialog asking for the excel to open/save etc... It doesnt happen why... Now it doesnt create the excel file Why.... My Applet code is...
1
by: Wayne's World | last post by:
hi everyone, i have a big problem, writing a image from my applet to my apache webserver. i tried three way's of writing that file. every way was described in forums to solve this problem, but...
5
by: Rowland | last post by:
Hi, I know this question has prob. been asked a million times, but I couldn't find it in the FAQ, so here goes : I'm trying to write a Java applet to call a dll that resides on the web server...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
8
by: Papa.Coen | last post by:
After repeatedly calling/using a Dictionary I get a StackOverflowError. What am I doing wrong? The situation is as follows: I have ruler class, this class contains some member variables,...
2
by: Richard Maher | last post by:
Hi, Can someone please tell me the strategy(ies) used by Java (the Security Manager or whatever) to determine if a given IP address conforms to the definition of the codebase from which an...
5
by: not_a_commie | last post by:
DataContractSerializer.ReadObject creates an object without calling any constructors. It doesn't require a parameterless constructor like all other deserialization implementations I've ever seen or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.