473,669 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Applet: StackOverflowEr ror when calling readObject()

4 New Member
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 3531
BigDaddyLH
1,216 Recognized Expert Top Contributor
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
verteidi
4 New Member
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 Recognized Expert MVP
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
Feb 1 '08 #4
verteidi
4 New Member
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
verteidi
4 New Member
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.
Feb 1 '08 #6

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

Similar topics

3
30825
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, I get a java.lang.StackOverflowError?? I kinda know why its happening; I think it calls the same equals method and
0
1729
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 ------------------------------------------------------------------------------ URL url =new URL("http://localhost:8080/portal/servlet/com.kbs.framework.client.gui.ReportServlet");
1
4914
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 non of them worked and i don't know why. i'll give you the code of my writing-methods and describe, what happen when i test them, in order someone of you can give me a usefull tip, where the problem is. as inputparameter i give my method a new...
5
13642
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 (running IIS 6). I've written a little test applet that should call a helloWorld function in the dll, but when I use System.loadLibrary, it gives me this security warning :
8
3374
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 problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if the Java method is called just once and then the page is refreshed. FireFox does not crash at all...
8
2908
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, encapsulated properties. SOme of those are calculated when get is called. These kind of properties are actually Cell classes which have a Calculation class attached. All Cell properties are stored in a Dictionary <nameEnum, Cell>
2
2645
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 applet was retrieved? For example, if an Applet was loaded from mycluster.mydomain.com, and "mycluster" was a cluster alias that was using DNS load-balancing (or round-robin or a.n.other distribution technique) to distribute client connections among...
5
5525
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 heard about. That's just weird. How do they do it? What's more weird, though, is that they don't initialize any fields. That leads to strange bugs. Of course that's why they have the OnDeserialized attribute -- you need to initialize your...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.